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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 GetDate() issue
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 02/28/2014 :  04:18:55  Show Profile  Reply with Quote
HI all

I need some help

Aim -
I am trying to get today’s date displayed as the following “2014-02-28T23:00:00.000Z”
If i use the getdate() it displays the date as “2014-02-28 09:14:32.967”

Anyone know how i can get the getdate() to be displayed as “2014-02-28T23:00:00.000Z”


Looking forward to your response

Regards

waterduck
Aged Yak Warrior

Malaysia
962 Posts

Posted - 02/28/2014 :  04:24:30  Show Profile  Reply with Quote
this 1?
SELECT CONVERT(VARCHAR, GETDATE(), 127)
2014-02-28T17:23:57.567
http://msdn.microsoft.com/en-us/library/ms187928%28SQL.90%29.aspx
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 02/28/2014 :  04:43:05  Show Profile  Reply with Quote
Hi Waterduck

That’s brilliant,
I want to produce a new column called “Past Date”
Past date needs to look at this CONVERT(VARCHAR, GETDATE(), 127) and go back 12 weeks.

Do you know what that calculation would be ?
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17642 Posts

Posted - 02/28/2014 :  04:49:40  Show Profile  Reply with Quote
use DATEADD() function


KH
Time is always against us

Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 02/28/2014 :  04:55:14  Show Profile  Reply with Quote
im trying to do this DATEADD(wk,CONVERT(VARCHAR, GETDATE(), 127),-12)

and i get this error

Msg 8116, Level 16, State 1, Line 1
Argument data type varchar is invalid for argument 2 of dateadd function.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17642 Posts

Posted - 02/28/2014 :  04:56:37  Show Profile  Reply with Quote
you should use dateadd() first before convert()


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000