Get first day and last day of current month

select

    DATEADD(month,datediff(month,’20000101′,GETDATE()),’20000101′) as FirstDayOfMonth,

    DATEADD(month,datediff(month,’20000131′,GETDATE()),’20000131′) as LastDayOfMonth

Edited:

In SQL Server 2012, a new EOMONTH is introduced:

SELECT EOMONTH(‘2012-08-24’)

Result:

2012-08-31

This function also takes a parameter as adjustment:

SELECT EOMONTH(‘2012-08-24’,1)

Returns: 2012-09-30

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s