I have designed a standalone web app located on windows azure virtual machine, which talks to a sql database located on my 123-reg vps.
Records are saved with a date stamp using .SQLdateTime
When I run my web app via my mobile phone or pc I get gmt rather than british summer time (ie the time stamp saved to the SQL being 1 hr earlier than my local time).
The application will be accessed globally and needs to provide a datestamp with the local time.
Frederic, this method is fine, but what about time zones that have daylight savings time? How do you set the offset such that it is always correct in such time zones?
Hi Louis - though this isnt spelled out in the LR, it appears to me that GMTOffset information is pulled from the local operating system settings. So if the local OS respects daylight savings time, the Date.GMTOffset does as well.
James - as far as getting UTC time, you can set your servers timezone to UTC or you can set a date object to the current date/time on the server and then set its GMTOffset to 0, that will convert the date/time stored in the date object to a UTC timezone value. Something like:
dim d as new date //automatically set to the current date/time by being instantiated
d.GMTOffest = 0 //converts the stored date/time to the corresponding UTC value
date_string_for_SQL = d.SQLdateTime //creates an SQL Date formatted string
As far as getting date information. If youre hosting your own server, you can probably rely on its date settings to be correct. You can also query an NTP server, which will return a UTC timestamp. Greg OLone from Xojo recently shared on the forums, an NTP class he wrote years ago. Ive cleaned it up a bit for Xojo. It demonstrates some of these ideas.
I think Anthony answered those questions very well.
Consider storing dates/times with GMTOffset set to 0 so regardless of where the database resides, or gets moved to, the date/time is always GMT/UTC. When it is presented to users, it can then be converted to their local time zone.