Joseph Michael Pesch
VP Programming

SQL Server Get First and Last Day's of Previous, Current and Next Month

by 10. January 2012 09:55

 

select

  [First Day of Previous Month] =

  convert(varchar(25)

  , dateadd(dd, -(day(getdate())-1)

  , dateadd(mm, -1, getdate()))

  , 101)

, [Last Day of Previous Month] =

  convert(varchar(25)

  , dateadd(dd, -(day(getdate()))

  , getdate())

  ,101)

, [First Day of Current Month] =

  convert(varchar(25)

  , dateadd(dd, -(day(getdate())-1)

  , getdate())

  , 101)

, [Last Day of Current Month] =

  convert(varchar(25)

  , dateadd(dd, -(day(dateadd(mm, 1, getdate())))

  , dateadd(mm, 1, getdate()))

  , 101)

, [First Day of Next Month] =

  convert(varchar(25)

  , dateadd(dd, -(day(dateadd(mm, 1, getdate()))-1)

  , dateadd(mm, 1, getdate()))

  , 101)

, [Last Day of Next Month] =

  convert(varchar(25)

  , dateadd(dd, -(day(dateadd(mm, 1, getdate())))

  , dateadd(mm, 2, getdate()))

  , 101)

 

Tags:

SQL Server

Comments are closed