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)
 Date & Time

Author  Topic 

tyekhan786
Starting Member

9 Posts

Posted - 2014-03-31 : 02:29:35
I have a Date& time field as below
26/03/2014 16:41:02
but i need to add to letters in it as show below,

26/03/2014T16:41:02Z

Thanks

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-03-31 : 02:43:18
[code]
declare @dtDate as datetime

set @dtDate='2014/03/26 16:41:02'


select convert(varchar(10),@dtDate,103)+'T '+convert(varchar(15),@dtDate,108)+'Z'
[/code]

output:
[code]
26/03/2014T 16:41:02Z
[/code]

S


sabinWeb MCP
Go to Top of Page

tyekhan786
Starting Member

9 Posts

Posted - 2014-03-31 : 08:08:35
Thanks the below only works for 1 date, in the table i have different date & time, i just need the datetime to be in the below format

YYYY-MM-DDTHH:MM:SSZ

Current format is
YYYY-MM-DD HH:MM:SS

quote:
Originally posted by stepson


declare @dtDate as datetime

set @dtDate='2014/03/26 16:41:02'


select convert(varchar(10),@dtDate,103)+'T '+convert(varchar(15),@dtDate,108)+'Z'


output:

26/03/2014T 16:41:02Z


S


sabinWeb MCP

Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-03-31 : 08:45:36
SELECT convert(varchar(10),YourColumn,103)+'T'+convert(varchar(15),YourColumn,108)+'Z'
FROM YourTable



sabinWeb MCP
Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-03-31 : 09:09:48
SELECT convert(varchar(30),YourColumn,127)
FROM YourTable


sabinWeb MCP
Go to Top of Page
   

- Advertisement -