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

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...