Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store GMT dates on a US server

I'm from the UK, and have recently deployed a website on WinHost's Basic Package.

When using DateTime.Now() in C#, or GETDATE() in SQL, these are both returning something like GMT-8 (because the server is hosted in the US).

I think I'm a bit limited in terms of permissions on the server (for example I can't change my SQL Login Language).

What is the best method of storing these dates in GMT?

like image 424
Curtis Avatar asked Jan 18 '26 21:01

Curtis


2 Answers

use DateTime.UtcNow and store as it is database. When reading from database assume UTC and convert into UK time using TimeZoneInfo class. Note that the SQL should not contain any information about time zone offsets.

like image 147
AYK Avatar answered Jan 21 '26 11:01

AYK


In SqlServer use getUtcDate() to store all your datetime values. You can convert it to required timezone in your .NET application.

like image 40
ajay swamy Avatar answered Jan 21 '26 11:01

ajay swamy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!