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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date & Time
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tyekhan786
Starting Member

United Kingdom
9 Posts

Posted - 03/31/2014 :  02:29:35  Show Profile  Reply with Quote
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

Romania
545 Posts

Posted - 03/31/2014 :  02:43:18  Show Profile  Reply with Quote

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

tyekhan786
Starting Member

United Kingdom
9 Posts

Posted - 03/31/2014 :  08:08:35  Show Profile  Reply with Quote
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

Romania
545 Posts

Posted - 03/31/2014 :  08:45:36  Show Profile  Reply with Quote
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

Romania
545 Posts

Posted - 03/31/2014 :  09:09:48  Show Profile  Reply with Quote
SELECT convert(varchar(30),YourColumn,127)
FROM YourTable


sabinWeb MCP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000