View Single Post

   
  #2 (permalink)  
Old 02-29-2008, 08:29 AM
Stu
 
Posts: n/a
Default Re: Code for 1st day & the Last day of the Previous Month

If you don't have a calendar table (which can be very helpful for
situations like this), you can do it on-the-fly using SQL Server like
so:


SELECT DATEADD(m, -1, FirstOfCurrentMonth) as FirstOfPreviousMonth,
DATEADD(d, -1, FirstOfCurrentMonth) as LastOfPreviousMonth
FROM (SELECT CONVERT(smalldatetime,DATENAME(m, GetDate())
+ ' 1,' + DATENAME(yyyy, GETDATE())) as FirstOfCurrentMonth) a

Of course, you'll want to do the formatting on the client side.

HTH,
Stu

Reply With Quote