select วันสุดท้ายของเดือน, day in month


—-Last Day of Previous Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
LastDay_PreviousMonth
—-Last Day of Current Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
LastDay_CurrentMonth
—-Last Day of Next Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))
LastDay_NextMonth

Advertisements
1 comment
  1. — select dayofyear — How many day of year ,u can change "getdate()" to other datetime select DATEDIFF(DAY , DATEADD(D,-DAY(getdate())+1, DATEADD(MM,-MONTH(getdate())+1,getdate())) ,DATEADD(YEAR,1, DATEADD(D,-DAY(getdate())+1, DATEADD(MM,-MONTH(getdate())+1,getdate()))) )

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

%d bloggers like this: