<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: DateTime to DateTimeOffset</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/datetime-to-datetimeoffset/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/datetime-to-datetimeoffset/</link>
	<description></description>
	<lastBuildDate>Wed, 19 Jun 2013 04:33:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: tracker1</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/datetime-to-datetimeoffset/#comment-112019</link>
		<dc:creator>tracker1</dc:creator>
		<pubDate>Mon, 08 Oct 2012 20:37:32 +0000</pubDate>
		<guid isPermaLink="false">#comment-112019</guid>
		<description><![CDATA[SELECT&#160;&lt;div&gt;&#160; TODATETIMEOFFSET(&lt;div&gt;&#160; &#160; [ColumnName]&lt;/div&gt;&lt;div&gt;&#160; &#160; ,datepart( tz, sysdatetimeoffset() )&lt;/div&gt;&lt;div&gt;&#160; )&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;datepart(tz,sysdatetimeoffset()) &#160;gets you the local offset (assuming you used GETDATE() to insert the dates. &#160;TODATETIMEOFFSET converts the column to a version with offset information. &#160;you could use &#039;+hh:nn&#039; or &#039;-nnn&#039; formatting if the offset is known in your conversion. &#160;I&#039;m wrapping this in a SWITCHOFFSET( result, &#039;+00:00&#039; ) to convert to UTC based datetimeoffsets in my results.&lt;/div&gt;&lt;/div&gt;]]></description>
		<content:encoded><![CDATA[<p>SELECT&nbsp;
<div>&nbsp; TODATETIMEOFFSET(
<div>&nbsp; &nbsp; [ColumnName]</div>
<div>&nbsp; &nbsp; ,datepart( tz, sysdatetimeoffset() )</div>
<div>&nbsp; )</div>
<div></div>
<div>datepart(tz,sysdatetimeoffset()) &nbsp;gets you the local offset (assuming you used GETDATE() to insert the dates. &nbsp;TODATETIMEOFFSET converts the column to a version with offset information. &nbsp;you could use &#8216;+hh:nn&#8217; or &#8216;-nnn&#8217; formatting if the offset is known in your conversion. &nbsp;I&#8217;m wrapping this in a SWITCHOFFSET( result, &#8216;+00:00&#8242; ) to convert to UTC based datetimeoffsets in my results.</div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/datetime-to-datetimeoffset/#comment-76502</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Mon, 26 Apr 2010 19:53:27 +0000</pubDate>
		<guid isPermaLink="false">#comment-76502</guid>
		<description><![CDATA[Doh - disregard the algorthm in the last post...

As Carlosdl says, the SwitchOffset function can be used, and is a lot cleaner:

declare @MyDateTime   datetime
declare @MyDTOffset   datetimeoffset

set @MyDTOffset = switchoffset(convert(datetimeoffset,@MyDateTime), &#039;-09:00&#039;)

Same general comments, but easier to apply.

Obviously, you would need to figure out the appropriate offset to apply.]]></description>
		<content:encoded><![CDATA[<p>Doh &#8211; disregard the algorthm in the last post&#8230;</p>
<p>As Carlosdl says, the SwitchOffset function can be used, and is a lot cleaner:</p>
<p>declare @MyDateTime   datetime<br />
declare @MyDTOffset   datetimeoffset</p>
<p>set @MyDTOffset = switchoffset(convert(datetimeoffset,@MyDateTime), &#8216;-09:00&#8242;)</p>
<p>Same general comments, but easier to apply.</p>
<p>Obviously, you would need to figure out the appropriate offset to apply.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/datetime-to-datetimeoffset/#comment-76501</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Mon, 26 Apr 2010 19:47:19 +0000</pubDate>
		<guid isPermaLink="false">#comment-76501</guid>
		<description><![CDATA[You could create the data with an offset (in a new column) by converting the datetime value to a string, appending a &quot;known&quot; offset, and then converting to a datetimeoffset datatype.

declare @MyOldDateTime   datetime
declare @MyNewDTOffset  datetimeoffset

set @MyNewDTOffset = convert(datetimeoffset(convert(varchar(32),@MyOldDateTime,120) + &#039;-09:00&#039;)

This is pretty easy to do - unless your data was recorded in a location that uses Daylight Savings (which is most of the world).

If you are in a DST area, you would need to take the old date/time, determine if it was within the DST date window, and add the offset accordingly.  Also, for those records between 0200 and 0300 at the DST time change points, how would you know whether to add the Standard or Daylight offset?  You will probably have to decide to either use DST after 0200 or after 0300 on those dates and live with the fact that some of the offsets will be incorrect for those windows.

Also, don&#039;t forget that the date of change for DST changed itself a couple of years ago, so your six years of data contain records with the old DST date range as well as the new range.

If I really had to do this, I would use a non-blocking cursor to find the records not yet converted (perhaps where the datetimeoffset column was null) and update chunks of records (500-1000) at a time to minimize rollback segment sizes and table locking issues.]]></description>
		<content:encoded><![CDATA[<p>You could create the data with an offset (in a new column) by converting the datetime value to a string, appending a &#8220;known&#8221; offset, and then converting to a datetimeoffset datatype.</p>
<p>declare @MyOldDateTime   datetime<br />
declare @MyNewDTOffset  datetimeoffset</p>
<p>set @MyNewDTOffset = convert(datetimeoffset(convert(varchar(32),@MyOldDateTime,120) + &#8216;-09:00&#8242;)</p>
<p>This is pretty easy to do &#8211; unless your data was recorded in a location that uses Daylight Savings (which is most of the world).</p>
<p>If you are in a DST area, you would need to take the old date/time, determine if it was within the DST date window, and add the offset accordingly.  Also, for those records between 0200 and 0300 at the DST time change points, how would you know whether to add the Standard or Daylight offset?  You will probably have to decide to either use DST after 0200 or after 0300 on those dates and live with the fact that some of the offsets will be incorrect for those windows.</p>
<p>Also, don&#8217;t forget that the date of change for DST changed itself a couple of years ago, so your six years of data contain records with the old DST date range as well as the new range.</p>
<p>If I really had to do this, I would use a non-blocking cursor to find the records not yet converted (perhaps where the datetimeoffset column was null) and update chunks of records (500-1000) at a time to minimize rollback segment sizes and table locking issues.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/datetime-to-datetimeoffset/#comment-76497</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Mon, 26 Apr 2010 15:14:01 +0000</pubDate>
		<guid isPermaLink="false">#comment-76497</guid>
		<description><![CDATA[The sofware being use was not mentioned, but as it mentions a &#039;table&#039;, a data type, and over a billion of rows, it is for sure referring to a database, and DateTimeOffset is a SQL Server 2008 data type.

In this case, the offset is not a difference between a given date and a base date, but a Time zone offset, which ranges from -14:00 to 14:00.]]></description>
		<content:encoded><![CDATA[<p>The sofware being use was not mentioned, but as it mentions a &#8216;table&#8217;, a data type, and over a billion of rows, it is for sure referring to a database, and DateTimeOffset is a SQL Server 2008 data type.</p>
<p>In this case, the offset is not a difference between a given date and a base date, but a Time zone offset, which ranges from -14:00 to 14:00.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chippy088</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/datetime-to-datetimeoffset/#comment-76430</link>
		<dc:creator>chippy088</dc:creator>
		<pubDate>Sat, 24 Apr 2010 09:28:42 +0000</pubDate>
		<guid isPermaLink="false">#comment-76430</guid>
		<description><![CDATA[Not knowing exactly why you would want to convert a date to an offset, makes a solution difficult to define. Made harder by the fact that you haven&#039;t mentioned any of the basic facts to take into consideration like

What program was used stored the data.
How big is/are the blocks of data you want to access.
Will the integrity of the data be conpromised by breaking it down into managable chunks.

Dates are stored as a number, it is only when we humans want to understand them that the formatting is used. (i.e. dd/mm/yyyy etc)

If you want to convert all the dates to an offset of, say the very first date, then you could try something like this.

date_offset = date_to_convert - base_date

Notice I haven&#039;t made it language specific. If you import the dates into an unformatted excel sheet you might see the number which represents the date.

If you have a billion dates to work on, bear in mind,  excel will not work well under a load like that.

You could write a VBA app to go through the list doing the convertions, (working on a copy of course,) and see how it goes.

Sorry I can&#039;t give a more specific answer, but now you have an idea how it could be done, good luck.]]></description>
		<content:encoded><![CDATA[<p>Not knowing exactly why you would want to convert a date to an offset, makes a solution difficult to define. Made harder by the fact that you haven&#8217;t mentioned any of the basic facts to take into consideration like</p>
<p>What program was used stored the data.<br />
How big is/are the blocks of data you want to access.<br />
Will the integrity of the data be conpromised by breaking it down into managable chunks.</p>
<p>Dates are stored as a number, it is only when we humans want to understand them that the formatting is used. (i.e. dd/mm/yyyy etc)</p>
<p>If you want to convert all the dates to an offset of, say the very first date, then you could try something like this.</p>
<p>date_offset = date_to_convert &#8211; base_date</p>
<p>Notice I haven&#8217;t made it language specific. If you import the dates into an unformatted excel sheet you might see the number which represents the date.</p>
<p>If you have a billion dates to work on, bear in mind,  excel will not work well under a load like that.</p>
<p>You could write a VBA app to go through the list doing the convertions, (working on a copy of course,) and see how it goes.</p>
<p>Sorry I can&#8217;t give a more specific answer, but now you have an idea how it could be done, good luck.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.036 seconds using memcached
Object Caching 323/329 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-19 07:59:26 -->