Wednesday, April 16, 2014

SQL - First and last day of the month

-- First day of the last month
SELECT DATEADD(mm, DATEDIFF(m,0,GETDATE())-1,0);

-- Last day of the last month
SELECT DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())  ,0));

No comments:

Post a Comment