A Journey 2 Eternity

Find the first date, last date and total days of a month

Posted on: November 16, 2011

DECLARE @Date datetime
SET @Date = '2011/11/16'
SELECT  DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS 'First day of the week',
DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last day of the week',
DAY(DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS 'Total day of the month'
Advertisements
Tags: ,

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

Pages

Categories

November 2011
M T W T F S S
« Jun   Dec »
 123456
78910111213
14151617181920
21222324252627
282930  

Blog Stats

  • 26,968 hits
%d bloggers like this: