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
 Previous MTD

Author  Topic 

dz0001
Starting Member

35 Posts

Posted - 2012-05-18 : 15:36:28
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

15732 Posts

Posted - 2012-05-18 : 15:45:18
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

35 Posts

Posted - 2012-05-18 : 16:45:15
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

15732 Posts

Posted - 2012-05-18 : 16:48:20
Whooops:
SELECT DATEADD(month, -1, GETDATE())
Go to Top of Page
   

- Advertisement -