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
 General SQL Server Forums
 New to SQL Server Programming
 Date function Help

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2013-03-13 : 05:11:02
Hey guys

Sorry to bother you so early in the morning, but i need some help and advice.
This is my table
SELECT TOP 5
[FDMSAccountNo]
,[Open_Date]
FROM [FDMS].[dbo].[Dim_Outlet]

Which produces the following results
FDMSAccountNo Open_Date
878000000884 20030521
878000001882 20090709
878000002880 20090709
878000003888 20090709
878000004886 20090709
I want to change the open date into the following format “2003-05-21T12:00:00Z”

Required outcome
FDMSAccountNo Open_Date
878000000884 2003-05-21 T12:00:00Z
878000001882 2009-07-09 T12:00:00Z
878000002880 2009-07-09 T12:00:00Z
878000003888 2009-07-09 T12:00:00Z
878000004886 2009-07-09 T12:00:00Z

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-13 : 06:39:25
this should be done at the front end application layer as its a presentation issue. Handling this in sql end will require casting to varchar which is bit of an overkill and will make further date manipulation with these values difficult

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Robowski
Posting Yak Master

101 Posts

Posted - 2013-03-13 : 06:45:14
Sorry if this double posts, my posts don't seem to be showing up.

You probably want to output it for xml datetime 126

check the below link for a full list of options. You may need to add a +'z' at the end though.

http://www.blackwasp.co.uk/SQLDateTimeFormats.aspx
Go to Top of Page
   

- Advertisement -