Sunday, August 30, 2009

MCTS 70-433 Datetime data type and time-zones (datetimeoffset)



The standard datetime data type doesn't include time-zones (GMT, CET, ...), for this you need datetimeoffset ... to work with international timezones, you need to work with the datetimeoffset datatype:

The following table lists the supported ISO 8601 string literal formats for datetimeoffset. For information about alphabetical, numeric, unseparated and time formats for the date and time parts of datetimeoffset, see date (Transact-SQL) and time (Transact-SQL).


ISO 8601

Description

YYYY-MM-DDThh:mm:ss[.nnnnnnn][{+|-}hh:mm]

These two formats are not affected by the SET LANGUAGE and SET DATEFORMAT session locale settings. Spaces are not allowed between the datetimeoffset and the datetime parts.

YYYY-MM-DDThh:mm:ss[.nnnnnnn]Z (UTC)

This format by ISO definition indicates the datetime portion should be expressed in Coordinated Universal Time (UTC). For example, 1999-12-12 12:30:30.12345 -07:0


Time Zone Offset

A time zone offset specifies the zone offset from UTC for a time or datetime value. The time zone offset can be represented as [+|-] hh:mm:

  • hh is two digits that range from 00 to 14 and represent the number of hours in the time zone offset. 
  • mm is two digits, ranging from 00 to 59, that represent the number of additional minutes in the time zone offset. 
  • + (plus) or – (minus) is the mandatory sign for a time zone offset. This indicates whether the time zone offset is added or subtracted from the UTC time to obtain the local time. The valid range of time zone offset is from -14:00 to +14:00. 


http://msdn.microsoft.com/en-us/library/bb630289.aspx


No comments: