Calculate First day of given date

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 913
SQL Server 2012 is having in-bulit EOMONTH() date function to get the end of month;

The below is the query to get first day of month...

DECLARE @Date datetime = '2015-01-28'
SELECT @Date GivenDate, DATEADD(mm,DATEDIFF(mm,0,@Date),0) FirstDayOfGivenMonth



OutPut:
GivenDate 	         FirstDayOfGivenMonth  
2015-01-28 00:00:00.000 2015-01-01 00:00:00.000

Comments or Responses

Login to post response