AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Monday 4 January 2016

Get first day & last day date of provided date in SQL

We are calculating first day & the last day of giving month date. Most of the SQL procedures are using date validation, hope this query will helpful for you.


Last Day Of Month
DECLARE @date DATETIME
SET @date='2015-03-04'
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@date)), DATEADD(m,1,@date))
            AS LastDayOfMonth
First Day Of Month
DECLARE @date DATETIME
    SET @date='2015-03-04'
SELECT DATEADD(dd,-(DAY(@date)-1),@date)
            AS FirstDayOfMonth

0 comments :

Post a Comment

  • Popular Posts
  • Comments