Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Previous date
Message
 
 
To
11/10/2011 09:06:20
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01526025
Message ID:
01526029
Views:
73
This message has been marked as the solution to the initial question of the thread.
>I would expect the date
>
>2011-09-11 14:01:37.963
>
>minus 4 years
>
>2007-09-11 14:01:37.963
>
>then the previous 1st October is 2006

I see, I think I misread the original requirement.

In this case:
DECLARE @testdate datetime

SET @testdate = DATEADD(MONTH,-2,CURRENT_TIMESTAMP )
SELECT CASE WHEN RIGHT(CONVERT(VARCHAR(10), @testdate, 112) ,4) >'1001' 
                THEN CONVERT(datetime,LTRIM(YEAR(@testdate)-4) + '1001')

         ELSE CONVERT(datetime,LTRIM(YEAR(@testdate)-5) + '1001') END
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