October 26, 2012 at 8:39 am
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,
October 26, 2012 at 8:47 am
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)
October 26, 2012 at 8:48 am
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)
October 26, 2012 at 8:50 am
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