MS SQL Tips & Tricks

How to find first and last day of the month

The sample bellow shows how to find the start and end date of the month containing specified date.

declare @cDateTime datetime;
set @cDateTime = GetDate()

select dateadd( month, 
		datediff( month, 0, @cDateTime ), 
		0 ) as BeginOfTheMonth;
		 
select 	dateadd(d,-1,dateadd( month, 
			datediff( month, 0, @cDateTime )+1,0 
		)) as EndOfTheMonth

Learn more tricks

Add Comment

Comments

15th July 2021

cialis cheapest online prices

zivacle

2nd August 2021

buy cialis online reviews

zivacle

31st August 2021

http://buystromectolon.com/ - Stromectol

uribete

4th September 2021

Prix Propecia Nancy

stromectol msd

16th September 2021

http://buyplaquenilcv.com/ - hydroxychloroquine price per pill

Prusina

16th September 2021

http://buypriligyhop.com/ - Priligy

Stubmag

18th September 2021

Lasix

Huncalm