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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Compare Dates

Author  Topic 

dzabor
Posting Yak Master

138 Posts

Posted - 2010-02-10 : 13:10:07
I have a date that I need to compare to the previous first day of the previous month.

For example for the month of Feb I need the following: dbo.Activity.TRANSACTION_DATE < '01/01/2010' (the 01/01/2010 is the date I am trying to dynamically return for each month)

Thanks,
dz

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-10 : 13:13:33
dbo.Activity.TRANSACTION_DATE < DATEADD(mm,DATEDIFF(mm,0,GETDATE())-1,0)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-10 : 13:15:58
Also see

http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dzabor
Posting Yak Master

138 Posts

Posted - 2010-02-10 : 13:25:53
That worked great! Thanks!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-10 : 13:31:04
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-11 : 06:51:30
I recommend using "Month" rather than "mm" -= avoids confusion / ambiguity with Minute / Millisecond

i.e. DATEADD(Month,DATEDIFF(Month,0,GETDATE())-1,0)
Go to Top of Page
   

- Advertisement -