Home > SQL > T-SQL, find last day of current month

T-SQL, find last day of current month

I think this is one of the FAQ question for T-SQL programmer, and here is some quick sample 

Last Day of Previous Month

SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) 

Last Day of Current Month

SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))

Last Day of Next Month

SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))

Show name of the month:

select datename (mm, date_field)

Or if you want to only show the first three letters of the month:

select left(datename (mm, date_field), 3)

Categories: SQL Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.