Get Start and End Dates for a Month : day 1-14 or day 15 through the end of month (for date range filter)


  



declare @dt datetime=current_timestamp  

,@startdate date
,@enddate date


Set @startdate = Case when day(@dt)>=15 then  dateadd(month,datediff(month,0,@dt),0) else Dateadd(Day,14,dateadd(month,datediff(month,0,@dt)-1,0) )  END

Set @enddate = Case when day(@dt)>=15 then  Dateadd(day,14,dateadd(month,datediff(month,0,@dt),0)) else  dateadd(month,datediff(month,0,@dt),0)  End

print @startdate
print @enddate
 
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