Monday 15 December 2014

Get last date of month in sql SQL server






here is the solution

SELECT Dateadd(dd, -Day(Getdate()), Dateadd(mm, 1, Getdate())) 

you will get the result like














Replace  Getdate() function with your date will give you the last date that you want.


SELECT Dateadd(dd,-Day('2015/02/16'), Dateadd(mm, 1, '2015/02/16')) 


Result :

















Thank you. :)

No comments:

Post a Comment