Tjun Tjun - 2 months ago 9
SQL Question

SQL How do i change my batch_date column from first day of the month to last day of the month

I'm working in SQL Server Management Studio 2008. I have a column called BATCH_DATE which has entries in this format

2007-01-01 00:00:00
.
I need these to be changed into
2007-01-31 00:00:00
format. Please help.

Answer
DECLARE @Month Datetime
Set  @month='2007-01-01 00:00:00'
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@month)+1,0))
Comments