Bismillah...

Saturday, August 8, 2015

SQL - Get Last/First Date of The Month

This is my first posting about SQL. Yesterday, I've got something issue to how to get last/first date of the month. Then, I search on google and.. voilllaaaa.. I've got it~



- First Date -
SELECT DATEADD(s,+1,DATEADD(mm, DATEDIFF(m,0,GETDATE())-1,0))

- LastDate -
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))


That's All. Hope the code will work for u~






Source: http://blog.sqlauthority.com/2007/08/18/sql-server-find-last-day-of-any-month-current-previous-next/

No comments:

Post a Comment