这听起来很简单,但它并没有像我想的那样工作。 我正在尝试跟踪月份到目前为止的进度这是我的MTD代码
Startdate>=DATEADD(MONTH, DATEDIFF(MONTH, 0, Convert(date, getdate())), 0)
它非常简单。
对于上个月开始我使用: Startdate>= DATEADD(month, DATEDIFF(month, -1, getdate()) , 0)作为开始日期
对于当前标记我用过: Enddate>=DATEADD(month, DATEDIFF(month, 0, getdate()-30), 0)+datepart (day,getdate())
理想情况下,我想知道如果今天是第五个。 那个窗口发生了多少次销售。 那么我也想知道我们在上个月的同一时期是怎么做的。
我的问题是我发现在31个月后的几个月,29天我有问题。
是否有一个函数在一个月前给我相同的日期?
This sounded simple but it doesnt work like I thought. I am trying to track progress for Month to date Here is my code for MTD
Startdate>=DATEADD(MONTH, DATEDIFF(MONTH, 0, Convert(date, getdate())), 0)
Its extremely simple.
For Last Months Start I use: Startdate>= DATEADD(month, DATEDIFF(month, -1, getdate()) , 0) as the start date
and for the current marker I used this: Enddate>=DATEADD(month, DATEDIFF(month, 0, getdate()-30), 0)+datepart (day,getdate())
Ideally I want to know that if today is the 5th. How many sales took place in that window. then I want to also know how we did in the same period the last month.
My problem is I find on months with 31 days that follow months with 29 days I have issues.
Is there a function that gives me the same date a month ago ?
最满意答案
dateadd(month, -1, getdate())即dateadd(month, -1, '20150330')返回'2015-02-28'
如果上个月不存在确切日期,则返回月份的最后一天。
dateadd(month, -1, getdate())i.e. dateadd(month, -1, '20150330') returns '2015-02-28'
If exact day doesn't exist in previous month returns last day of month.
更多推荐
发布评论