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
 Datetime conversion

Author  Topic 

Makkaramestari
Starting Member

8 Posts

Posted - 2006-02-16 : 03:32:19
Hi!

I want to get current date and subtract 14 days from that date and return result as int in yyyymmdd-format.
How should I do that?

Thanks in advance, Makkaramestari

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-02-16 : 03:36:25
SELECT CONVERT(CHAR(8), DATEADD(day, -14, CURRENT_TIMESTAMP), 112)

Mark
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-16 : 04:15:26
Select DateAdd(day,Datediff(day,0,getdate()),-14)

To format it, use front end application (if you use it). Otherwsie use
Select convert(varchar,DateAdd(day,Datediff(day,0,getdate()),-14),112) as ConvertedDate



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -