Pages

Saturday, January 22, 2011

Let your database applications happily traverse timezones

Sometimes developers come across the situation where a datetime value is stored on each row in a table (for example, the created or last-modified datetime), and then subsequently this datetime value needs to be accessed and processed in some way by a client program. If the client program is such that it may be running in any arbitrary timezone (e.g. web users), it becomes difficult or impossible to be sure about when exactly the underlying row was created or modified. A standardized approach, using the UTC (Coordinated Universal Time), is required.


On the SQL Server side:
  • When storing a datetime in SQL Server, always generate the datetime in the SQL stored proc itself (in the INSERT or UPDATE statement); never pass it from the calling client program.
  • Always store the datetime as UTC and not local -- use the GETUTCDATE() function in SQL Server, not GETDATE()
  • For comparisons of current datetime against the datetime on a given row, again ONLY use the current UTC time generated by the SQL Server and not by the client app. To get the current server UTC time, you can create a simple stored proc that just returns the GETUTCDATE() value, perhaps as an OUTPUT parameter.
On the .NET client side:

  • Use DateTime.Compare method to compare the datetime values received from SQL Server
  • If you need to convert a UTC time returned by the server into the local time, for display purposes, use the DateTime.ToLocalTime method in your client application. This also automatically factors-in any Daylight Saving time rule in effect.
Observing these simple rules will ensure that the date/time comparisons remain valid and accurate in your database applications, whether they are deployed over local networks or over the Internet across the globe. A positive side-effect is also that if you move your server to a different timezone, the logic to handle UTC datetimes needs no change at all - just make sure the server system clock is set to its local timezone.

Happy coding!

PS: Why is "Coordinated Universal Time" abbreviated to UTC and not to CUT? Check out these links:

http://www.nist.gov/pml/div688/utcnist.cfm

http://en.wikipedia.org/wiki/Utc#Symbol.

2 comments:

  1. https://www.facebook.com/bantalsilikongrosir
    http://bantalsilikon01.blogspot.com/2014/12/a.html
    http://jualsangkarpleci.blogspot.com/2014/12/a.html
    http://kopiluwakliar01.blogspot.com/2014/12/a.html
    http://vvty.in/uncategorized/marinir-seo/

    http://marinirseo.blogspot.com/2014/12/a.html
    http://marinir-seo.blogspot.com/2014/12/a.html
    http://bumbu-pecel-malang.blogspot.com/2014/12/a.html
    http://distro-seo.blogspot.com/2014/12/a.html
    http://restoran-seo.blogspot.com/2014/12/a.html
    http://bantalmalangmurah.blogspot.com/2014/12/a.html
    http://distrobantal.blogspot.com/2014/12/a.html
    http://kesethandukmalang.blogspot.com/2014/12/a.html

    https://www.facebook.com/bantalsilikongrosir
    http://bantalsilikon01.blogspot.com/http://jualsangkarpleci.blogspot.com/http://kopiluwakliar01.blogspot.com/http://vvty.in/uncategorized/marinir-seo/http://marinirseo.blogspot.com/http://marinir-seo.blogspot.com/http://bumbu-pecel-malang.blogspot.com/http://distro-seo.blogspot.com/http://restoran-seo.blogspot.com/http://bantalmalangmurah.blogspot.com/http://distrobantal.blogspot.com/http://kesethandukmalang.blogspot.com/

    http://tasya.marinirseo.web.id/?p=4http://caca.marinirseo.web.id/?p=4http://anne.marinirseo.web.id/?p=4http://jeannet.marinirseo.web.id/?p=4http://jelita.marinirseo.web.id/?p=4http://brenda.marinirseo.web.id/?p=1http://ruth.marinirseo.web.id/?p=4http://tasya1.marinirseo.web.id/?p=4http://caca1.marinirseo.web.id/?p=4http://anne1.marinirseo.web.id/?p=4http://jeannet1.marinirseo.web.id/?p=4http://jelita1.marinirseo.web.id/?p=4http://brenda1.marinirseo.web.id/?p=1http://ruth1.marinirseo.web.id/?p=4http://tasya2.marinirseo.web.id/?p=4http://caca2.marinirseo.web.id/?p=5http://anne2.marinirseo.web.id/?p=4http://jeannet2.marinirseo.web.id/?p=4http://jelita2.marinirseo.web.id/?p=4http://brenda2.marinirseo.web.id/?p=1http://ruth2.marinirseo.web.id/?p=4http://ruth3.marinirseo.web.id/?p=3http://jelita3.marinirseo.web.id/?p=3http://brenda3.marinirseo.web.id/?p=3http://jeannet3.marinirseo.web.id/?p=3http://anne3.marinirseo.web.id/?p=3http://caca3.marinirseo.web.id/?p=3http://tasya3.marinirseo.web.id/?p=3http://tasya4.marinirseo.web.id/?p=4http://caca4.marinirseo.web.id/?p=4http://anne4.marinirseo.web.id/?p=4http://jeannet4.marinirseo.web.id/?p=4http://jelita4.marinirseo.web.id/?p=4http://brenda4.marinirseo.web.id/?p=6http://ruth4.marinirseo.web.id/?p=4http://tasya5.marinirseo.web.id/?p=4http://caca5.marinirseo.web.id/?p=4http://anne5.marinirseo.web.id/?p=4http://jelita5.marinirseo.web.id/?p=4http://ruth5.marinirseo.web.id/?p=4
    http://tasya.marinirseo.web.id/http://caca.marinirseo.web.id/http://anne.marinirseo.web.id/http://jeannet.marinirseo.web.id/http://jelita.marinirseo.web.id/http://brenda.marinirseo.web.id/http://ruth.marinirseo.web.id/http://tasya1.marinirseo.web.id/http://caca1.marinirseo.web.id/http://anne1.marinirseo.web.id/http://jeannet1.marinirseo.web.idhttp://jelita1.marinirseo.web.id/http://brenda1.marinirseo.web.id/http://ruth1.marinirseo.web.id/http://tasya2.marinirseo.web.id/http://caca2.marinirseo.web.id/http://anne2.marinirseo.web.id/http://jeannet2.marinirseo.web.idhttp://jelita2.marinirseo.web.id/http://brenda2.marinirseo.web.id/http://ruth2.marinirseo.web.id/http://ruth3.marinirseo.web.id/http://jelita3.marinirseo.web.id/http://brenda3.marinirseo.web.id/http://jeannet3.marinirseo.web.id/http://anne3.marinirseo.web.id/http://caca3.marinirseo.web.id/http://tasya3.marinirseo.web.id/http://tasya4.marinirseo.web.id/http://caca4.marinirseo.web.id/http://anne4.marinirseo.web.id/http://jeannet4.marinirseo.web.id/http://jelita4.marinirseo.web.id/http://brenda4.marinirseo.web.id/http://ruth4.marinirseo.web.id/http://tasya5.marinirseo.web.id/http://caca5.marinirseo.web.id/http://anne5.marinirseo.web.id/http://jelita5.marinirseo.web.id/http://ruth5.marinirseo.web.id/

    ReplyDelete
  2. Thus, fashionable tradition puts an image in our heads that roulette is a recreation for the wealthy and the elite. Obviously, everybody desires to hitch this fancy group of individuals and really feel like they're a part of} the higher world. And with the invention of online roulette, it grew to become even easier to take action. At the same time, you’ll also ready to|be succesful of|have the flexibility to} spot the frequency of successful bets. Single numbers 코인카지노 pay the most, however getting a straight wager right is fairly difficult. Placing bets on a bunch of numbers increases your possibilities to win a spherical, however the odds are much lower.

    ReplyDelete