Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Convert This Date
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01448391
Message ID:
01448393
Views:
44
>I have 96K rows with a Month column. The data is in the format:
>
>
YYYY-MM-Mon
>
>So, '2009-11-Nov' is November, 2009 and '2009-02-Feb' is February. The middle 2 charaters are the month number.
>
>I need to convert these to the first saturday of the month. Anyone know of a way to do this?

Denis Gobo solution
DECLARE @GiGo VARCHAR(46)
SELECT @GiGo = '2010-02-Feb'
DECLARE @DATE DATETIME
 
SELECT @DATE = LEFT(@GiGo,7) + '-01'
 
-- not needed in this case
--SELECT @DATE=   DATEADD(mm, DATEDIFF(mm, 0, @DATE)+0, 0)
 
 
SELECT TOP 1 DATEADD(dd,number,@DATE) FROM master..spt_values
WHERE type = 'p'
and DATEPART(dw,DATEADD(dd,number,@DATE)) = 7
ORDER BY 1 ASC
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform