Unix Technical Forum

ISO dates?

This is a discussion on ISO dates? within the SQL Server forums, part of the Microsoft SQL Server category; --> To support an application, I am integrating it with with Sqlserver 2000. The task is simple: get the data ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 03:33 AM
php newbie
 
Posts: n/a
Default ISO dates?

To support an application, I am integrating it with with Sqlserver
2000. The task is simple: get the data at regular intervals, and
write it into a table dedicated for that application. One of the
fields I receive is a date, and it is formatted as an ISO date. A
sample value looks like this: "2004-07-09-15.37.52.077258".

SQLServer doesn't support this date format, though. The closest I
have found is the style code "21" or "121" which accepts input as
"yyyy-mm-dd hh:mi:ss.mmm". I have looked at using several replace()
and convert() calls but no solution yet.

Is there a way to transform the data to conform to this style accepted
by Sqlserver? I would like to do this in the INSERT statement itself
and not have to code application logic (i.e., user-defined function,
etc.) for it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 03:33 AM
Gert-Jan Strik
 
Posts: n/a
Default Re: ISO dates?

No, not without using complex CAST functions, UDFs, or INSTEAD OF
triggers.

I suggest you stick to the simplified ISO 8601 syntax, for example
"20040709 15:37:52.077". If you must, you can use
"2004-07-09T15:37:52.077", which will also alway work correctly on
version 2000 of SQL-Server.

Also note that SQL-Server will not accept more than 3 digits for
milliseconds.

HTH,
Gert-Jan


php newbie wrote:
>
> To support an application, I am integrating it with with Sqlserver
> 2000. The task is simple: get the data at regular intervals, and
> write it into a table dedicated for that application. One of the
> fields I receive is a date, and it is formatted as an ISO date. A
> sample value looks like this: "2004-07-09-15.37.52.077258".
>
> SQLServer doesn't support this date format, though. The closest I
> have found is the style code "21" or "121" which accepts input as
> "yyyy-mm-dd hh:mi:ss.mmm". I have looked at using several replace()
> and convert() calls but no solution yet.
>
> Is there a way to transform the data to conform to this style accepted
> by Sqlserver? I would like to do this in the INSERT statement itself
> and not have to code application logic (i.e., user-defined function,
> etc.) for it.


--
(Please reply only to the newsgroup)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 03:33 AM
Aaron W. West
 
Posts: n/a
Default Re: ISO dates?

You can't store time with higher resolution than 1/300th second (in
multiples of .010 + .000, .003 or .007) in a DATETIME column. Also, I think
it's generally better to do this in application logic, unless you have many
places where the time values are inserted. For example, Perl can do a lot
more with regular expressions than you can easily implement in T-SQL.

But this should work if the format never varies (eg. if your months and day
values are always 2 digits each, and the year always 4 digits)

declare @dt varchar(26)
set @dt = '2004-07-09-15.37.52.077258'
print left(@dt,10)+' '+replace(substring(@dt,12,12),'.',':')
select cast(left(@dt,10)+' '+replace(substring(@dt,12,12),'.',':') as
datetime)

"php newbie" <newtophp2000@yahoo.com> wrote in message
news:124f428e.0407091204.34f6390b@posting.google.c om...
To support an application, I am integrating it with with Sqlserver
2000. The task is simple: get the data at regular intervals, and
write it into a table dedicated for that application. One of the
fields I receive is a date, and it is formatted as an ISO date. A
sample value looks like this: "2004-07-09-15.37.52.077258".

SQLServer doesn't support this date format, though. The closest I
have found is the style code "21" or "121" which accepts input as
"yyyy-mm-dd hh:mi:ss.mmm". I have looked at using several replace()
and convert() calls but no solution yet.

Is there a way to transform the data to conform to this style accepted
by Sqlserver? I would like to do this in the INSERT statement itself
and not have to code application logic (i.e., user-defined function,
etc.) for it.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:34 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com