Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getdate() function is returning different result than DateTime.Now in dotnet

If I run these two functions I am getting different result. The datetime.Now in dotnet is showing the same result as it is showing in the system time while there is a difference of around 20 minutes if i use getdate()... what is the cause, and how to overcome this?

like image 514
learner123 Avatar asked Aug 19 '11 13:08

learner123


2 Answers

The 2 machines have different system times.

  • GETDATE gets time from the server where SQL Server is installed (where it runs).
  • DateTime.Now gets time from the App or Web server or your local PC.

Don't mix up "machine that sends GETDATE() command" and "machine that runs it".

like image 193
gbn Avatar answered Oct 23 '22 17:10

gbn


You can use the Windows Time Service to synchronize machine's clocks.

http://support.microsoft.com/kb/307897

like image 25
Steve Wellens Avatar answered Oct 23 '22 15:10

Steve Wellens