Date operations | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Date operations

Hi All
I had a problem with dates, i had a date , with that i want to get the monday and sunday of that week. is there any way…
Regards
Rajesh.
Check out DATEPART and DATEFIRST in books on line and you’ll be on your way. Dalton
Here’s a solution that will work regardless of the DATEFIRST setting<br /><pre id="code"><font face="courier" size="2" id="code"><br />DECLARE @TheDate DATETIME<br />SET @TheDate = ‘20060213’<br />–Monday<br />SELECT<br /> CAST(CONVERT(CHAR(<img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ />, @TheDate, 112) AS DATETIME)<br /> – DATEPART(WEEKDAY, @[email protected]@DATEFIRST-1) + 1 Last_Monday<br /> , CAST(CONVERT(CHAR(<img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ />, @TheDate, 112) AS DATETIME)<br /> – DATEPART(WEEKDAY, @[email protected]@DATEFIRST-1) Last_Sunday<br /> , CAST(CONVERT(CHAR(<img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ />, @TheDate, 112) AS DATETIME)<br /> – DATEPART(WEEKDAY, @[email protected]@DATEFIRST-1) + 7 Next_Sunday<br /></font id="code"></pre id="code"><br /><br /><br />–<br />Frank Kalis<br />Microsoft SQL Server MVP<br /<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a><br />Heute schon gebloggt?<a target="_blank" href=http://www.insidesql.de/blogs>http://www.insidesql.de/blogs</a><br />
]]>