Converting from globalized date/time format (maybe ISO8601) to SQL Server datetime type -


What is a stat format that represents a data time that is a SQL Pars and an offset (EST -> UTC example for).

I have a string from the user like:

  declared @ P1 varchar (50); Announce the DTKDet Time Datamyme; Set @ p1 = "2009-06-26 14: 30: 00.000Z-4: 00"; - Can be ISO 8601 - What do I do to convert @ P1? Set @utcDateTime = - should be "2009-06-26 18: 30: 00.000"  

I want to be able to convert the string to its UTC equivalent and it will be periodically I want to store on the farm. It is such that:

  select @ utcDateTime  

should generate it:

  "2009-06- In other words, I want to store a date time whose first string is the value of '2009-06-26 18:30'.  

In addition to this, we must believe that the server is not in the same timezone as the user (hence we can detect offset (gettime)), getutctime (). >

> I have tried to use the convert (...) and cast (as in the form of day-to-day), but there is no luck.

Is there any way to do this in SQL Server 2005?

Okay here is my try - it's fun Was: -)

  DECLARE @ datestr varchar (100) SET @dateestr = '2009-06-26 14: 30: 00.000z + 4: 00' Select @ date, DATEADD (mi, -1 * cast (SUBSTRING (@datestr, 25, 1) DATAFF (DATFF (@ DATASTER, 23) as DTDADF (IAT) DATFF (IM, '19 00-01-01', Cast (Substrating (@Dietester, 26.5) 2009-06- 26 14: 30: 00.000Z-4: 00 'SELECT @ datestr, DATEADD (mi, -1 * cast (SUBSTRING (@datestr, 25,1) +' 1 'AS) * DATEDIFF (mi,' 1 9 00-01-01 ', CAST (Substrating (@tatstrator, 26,5) as the time of day), CAST (LTT (@Dietestor, 23) DATTO M)) SET @dateestr = '2009-06-26 14:30: 00.000Z + 14: 00' Select @Dateaster, DATEADD (m, -1 * CAST (SUBSTRING (@datestr, 25,1) + 1 ' '), DATEDIFF (miles,' 19 00-01-01 ', CAST (SUBSTRING (@ datestr, 26, 5) as of day time), CAST (left (@datestr, 23) datetime SET @dateestr = '2009-06-26 14: 30: 00.000Z + 4: 30' Select @DueStart, DATEADD (mi, - 1 * Cast (Substrating (@tatester, 25,1) + '1' AS) * DATEDIFF (mi, '19 00-01-01', Cast (Substrating (@tatestar, 26.5) as the time of day), Cast (LEFT (@ datestr, 23) datetime SET @datestr = '2009-06-26 14: 30: 00.000Z-4: 30' Select @date Ster, DATEADD (mi, -1 * cast (as SUBSTRING (@dateestr, 25,1) + 1 ') * DATEDIFF (mi,' 19 00-01-01 ', cast (substrate (@datestr, 26,5) as the time of day), cast (datetime as left (@tatester, 23)) SET @dateestr = '2009-06-26 14: 30: 00.000Z + 14: 30' of Select @ date, DATEADD (mi, -1 * cast (SUBSTRING (@datestr, 25,1) + 1 'at atight) * DATEDIFF (mi,' 19 00-01-01 ', cast (substrate (@datester) , 26,5) as the time of day), CAST (Left (@Detestoster, 23) as the time of day))  

Returns:

  2009-06-26 14: 3: 00.000Z + 4: 00 2009-06-26 10: 30: 00. 000 2009-06-26 14: 30: 00.000Z-4: 00 2009-06-26 18: 30: 00.000 2009-06-26 14:30 30: 00.000Z + 14: 00 2009-06-26 00: 30: 00.000 2009-06-26 14: 30: 00.000Z + 4: 30 2009-06-26 10: 00: 00.000 2009-06-26 14:30 30: 00.000Z-4: 30 2009-06-26 19: 00: 00.000 2009-06-26 14: 30: 00.000 Sage + 14: 30 2009-06-26 00: 00: 00.000  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -