Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Previous date
Message
 
 
To
11/10/2011 08:50:56
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01526025
Message ID:
01526026
Views:
38
>Hi
>
>I'm being passed a date via a csv file.
>
>I want to insert into my database the previous October 1st of that date minus 4 years.
>
>So if my date is 1st January 2011 I'd want the 1st October 2006
>
>Any ideas on how I could get that.
>
>Thnaks

Do you just want to subtract 4 years from current date?

If so,
declare @PrevDate date
set @PrevDate = dateadd(year, -4, cast(CURRENT_TIMESTAMP as DATE)) -- SQL Server 2008+
If you always want October 1, then
select CONVERT(datetime,ltrim(year(CURRENT_TIMESTAMP)-4) + '1001') as PreviousDate
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform