SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Previous MTD
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dz0001
Starting Member

33 Posts

Posted - 05/18/2012 :  15:36:28  Show Profile  Reply with Quote
Hi There,

wondering if you can point me the right direction on

1. Current MTD (current month to date)
2. Previous MTD (previous month to date)

Many thanks

robvolk
Most Valuable Yak

USA
15559 Posts

Posted - 05/18/2012 :  15:45:18  Show Profile  Visit robvolk's Homepage  Reply with Quote
SELECT DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) AS MTD
SELECT DATEADD(month, DATEDIFF(month, 0, GETDATE())-1, 0) AS PrevMTD
Go to Top of Page

dz0001
Starting Member

33 Posts

Posted - 05/18/2012 :  16:45:15  Show Profile  Reply with Quote
robvolk,

Thanks for the script, but it seems returing first day of curent month and previous month. I am looking for previous MTD, for example, today is May 21, so previous MTD is April 21, is this possible?
Go to Top of Page

robvolk
Most Valuable Yak

USA
15559 Posts

Posted - 05/18/2012 :  16:48:20  Show Profile  Visit robvolk's Homepage  Reply with Quote
Whooops:
SELECT DATEADD(month, -1, GETDATE())
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000