learner123
learner123

Reputation: 243

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?

Upvotes: 5

Views: 2560

Answers (2)

gbn
gbn

Reputation: 432261

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".

Upvotes: 14

Steve Wellens
Steve Wellens

Reputation: 20620

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

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

Upvotes: 5

Related Questions