Storing a time zone value in SQL Server's datetime field

Q: Is there a way to store the time zone value in a datetime field in SQL Server? I receive the value of ‘12/1/2005 12:31:23 -5:00’ and when I try to store it in SQL it fails. Do I need to format the date/time differently, or I am forced to create a separate time zone field?

A: SQL Server does not support storing a timezone in a datetime field. However, to overcome that issue, you can convert all date/time values to the UTC timezone so you have a standard timezone to work with. When displaying the data to the user, you would then convert the time to the client’s timezone.

In regards to storing the value ‘12/1/2005 12:31:23 -5:00’ into SQL Server, try using the format '2005-08-09 00:00:00.000'.

Comments

Popular posts from this blog

Working with double quotes (") in VB.Net

Using VB Script to display part of an IP address

Object reference not set to an instance of an object when using HTMLEditorExtender