How to set Getdate() to 1st of month

  • Is there a way to select the getdate() function or any other function and have it return a value that sets the day to the first of the month? So 'select getdate()' would return '2012-10-01' instead of '2012-10-26' ?

    Thanks in advance,

  • select FirstDayOfMonth= dateadd(mm,datediff(mm,0,getdate()),0)

    select LastDayOfMonth= dateadd(mm,datediff(mm,-1,getdate()),-1)

    select FirstDayOfQuarter= dateadd(qq,datediff(qq,0,getdate()),0)

    select LastDayOfQuerter= dateadd(qq,datediff(qq,-1,getdate()),-1)

    select FirstDayOfYear= dateadd(yy,datediff(yy,0,getdate()),0)

    select LastDayOfYear= dateadd(yy,datediff(yy,-1,getdate()),-1)

  • You can use dateadd and datediff to get the first day of the current month from getdate() using something like this:

    select dateadd(m, DATEDIFF(m, 0, getdate()), 0)

  • Thank you for the quick replies SSCrazy and Mr or Mrs ...

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply