Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 dateadd()

Author  Topic 

jgrant
Yak Posting Veteran

69 Posts

Posted - 2007-03-22 : 18:48:32
If I am running a scheduled job at the first of the month and I want to run an update sequence for the previous month, i was essentially using this sql:

@startdate = dateadd(mm, -1, getdate())
@enddate = dateadd(dd, -1, getdate())

So, will the @enddate represent the last day in the previous month or will that not work?

The Yak Village Idiot

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-22 : 19:42:45
No. It will not work. Didn't you ever test it out at all ?

select @start_date = dateadd(month, datediff(month, 0, getdate()) -1, 0)
select @end_date = dateadd(month, datediff(month, 0, getdate()), -1)




KH

Go to Top of Page
   

- Advertisement -