Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 full ISO format?

Author  Topic 

lauramayer
Posting Yak Master

152 Posts

Posted - 2011-06-15 : 15:25:44
Good afternoon,

I need to format the date time into "Full ISO format" like so: CCYY-MM-DDTHH:MM:SS.ssssss

I tried CONVERT(VARCHAR(23), GETDATE(), 126) but that only gives me: 2011-06-15T15:25:19.243

Can someone tell me what I need to do?

Thanks

Laura

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-06-15 : 15:32:19
GETDATE()'s resolution is milliseconds, use SYSDATETIME() to return smaller increments.
Go to Top of Page

lauramayer
Posting Yak Master

152 Posts

Posted - 2011-06-15 : 15:45:03
Thanks for that. That doesn't do it for me though. I get this when I replace getdate() with SYSDATETIME() and that got me basically the same thing.

I got a little closer by doing this: CAST(GETDATE() AS datetimeoffset(6)) AS 'datetimeoffset'

That give me : 2011-06-15 15:40:19.243000 +00:00 which is the closest I've come but how to get the "T" in there.

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-06-15 : 15:46:28
CONVERT(char(26), SYSDATETIME(), 126)
Go to Top of Page

lauramayer
Posting Yak Master

152 Posts

Posted - 2011-06-15 : 16:03:05
Fantastic! Thanks so much.
Go to Top of Page
   

- Advertisement -