2

I have used a date time in my project. My project is client server and developed with c#.

Now, I want to get date time clients from SQL Server on server, that when the system date time client was in trouble, Application get current date time from server.

For example: A timer that each hour to run the SQL server following command:

SELECT CURRENT_TIMESTAMP

Edit: C# application get date time from SQL Server and each hour once, your update date time

2 Answers2

2
SELECT SYSDATETIME();

Check docs for more: https://msdn.microsoft.com/pl-pl/library/ms188383(v=sql.110).aspx

Although it would be simpler to just use DATETIME.NOW in C# instead of selecting this value from the database, but it depend on your setup.

Outshined
  • 709
  • 7
  • 22
0

You must

  • open a connection to sql server

  • execute a select command using that connection

  • get the proper value from the returned data

C#

qlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = "SELECT GETDATE() as CurrentTime";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.
user5328504
  • 734
  • 6
  • 21