DECLARE @mydate DATETIME
SELECT @mydate = getdate()
SELECT CONVERT(VARCHAR(25), DATEADD(DD, -DAY(@mydate-1), DATEADD(MM, -1, @mydate)), 101) ,
'First Day of Previous Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)),@mydate),101) ,
'Last Day of Previous Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101) AS Date_Value,
'First Day of Current Month' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25), DATEADD(DD, -7, @mydate), 101) AS Date_Value, 'Start Date of Previous Week' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25), DATEADD(DD, -1, @mydate), 101) AS Date_Value, 'End Date of Previous Week' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),@mydate,101) AS Date_Value, 'Today' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,
'Last Day of Current Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,1,@mydate)),101) ,
'First Day of Next Month'
Monday, November 24, 2008
SQL Tip: SQL Statement to find Business Dates
SQL Statement to find Business Dates, posted by Pinal Dave here. I have added my own logic of finding the 'First Day of Previous Month'.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment