Wednesday, 24 February 2021

How to get start and end date from month number and Year in sql server

 /////////////


declare @Year int=2020, @Month int=1

Select 'Month Name : '+ DateName( month , DateAdd( month , @Month , 0 ) - 1 )

select cast(dateadd(month, @Month - 1, dateadd(year, @Year - 1900, 0)) as date) [Start Date],

       cast(dateadd(month, @Month,dateadd(year, @Year - 1900, -1)) as date) [End Date]



////////////////// Result

Month Name : January

Start Date End Date

2020-01-01 2020-01-31


No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...