试图跟踪本月与上一年的进展情况(Trying to track progress this month vs Previous)

编程入门 行业动态 更新时间:2024-10-24 20:15:21
试图跟踪本月与上一年的进展情况(Trying to track progress this month vs Previous)

这听起来很简单,但它并没有像我想的那样工作。 我正在尝试跟踪月份到目前为止的进度这是我的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.

更多推荐

本文发布于:2023-08-04 10:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1414034.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进展情况   track   progress   month   Previous

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!