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
 GetDate() issue

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2014-02-28 : 04:18:55
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

982 Posts

Posted - 2014-02-28 : 04:24:30
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 - 2014-02-28 : 04:43:05
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)

17689 Posts

Posted - 2014-02-28 : 04:49:40
use DATEADD() function


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2014-02-28 : 04:55:14
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)

17689 Posts

Posted - 2014-02-28 : 04:56:37
you should use dateadd() first before convert()


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -