在 SQL Server Reporting Services (VB.Net) 中查找上一个日历月的第一天和最后一天
我正在 MS SQL Server Reporting Services 中创建报告,需要将默认的开始日期和结束日期报告参数设置为上一个日历月的第一个和最后一个日期,并且需要帮助。
该报告是在该月的第二个日历日生成的,我需要以下值:
上一个日历月
- 第一天
- 最后一天
我一直在使用 DateAdd,但没有成功创建表达式(据我所知,在 VB.NET 中)。我非常感谢您能给我的任何帮助!
I'm creating a report in MS SQL Server Reporting Services and need to set the default Start and End Date report parameters to be the first and last dates of the previous calendar month and need help.
The report is generated on the 2nd calendar day of the month and I need values for:
Previous Calendar Month
- first day
- last day
I've been working with DateAdd, but have not been successful at creating an Expression (in VB.NET as I understand it). I would really appreciate any help you can give me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
Randall,以下是我发现可以在 SSRS 中使用的 VB 表达式,以获取任何月份的第一天和最后一天,使用当前月份作为参考:
上个月的第一天:
本月的第一天:
下个月的第一天:
上个月的最后一天:
本月的最后一天:
下个月的最后一天:
VisualBasic
DateSerial(year,month,day)
函数的 MSDN 文档 解释了该函数接受超出year
预期范围的值,< code>month 和day
参数。这允许您指定有用的相对日期值。例如,Day
的值 0 表示“上个月的最后一天”。这是有道理的:那是当月第一天的前一天。Randall, here are the VB expressions I found to work in SSRS to obtain the first and last days of any month, using the current month as a reference:
First day of last month:
First day of this month:
First day of next month:
Last day of last month:
Last day of this month:
Last day of next month:
The MSDN documentation for the VisualBasic
DateSerial(year,month,day)
function explains that the function accepts values outside the expected range for theyear
,month
, andday
parameters. This allows you to specify useful date-relative values. For instance, a value of 0 forDay
means "the last day of the preceding month". It makes sense: that's the day before day 1 of the current month.这些功能对我非常有帮助——尤其是在设置订阅报告方面;但是,我注意到,当使用上面发布的当前月份的最后一天函数时,只要上个月与当前月份的天数相同,它就可以工作。我已经完成并测试了这些修改,希望它们将来能帮助其他开发人员:
日期公式:
查找上个月的第一天:
查找上个月的最后一天:
查找当月的第一天:
查找当月的最后一天:
These functions have been very helpful to me - especially in setting up subscription reports; however, I noticed when using the Last Day of Current Month function posted above, it works as long as the proceeding month has the same number of days as the current month. I have worked through and tested these modifications and hope they help other developers in the future:
Date Formulas:
Find the First Day of Previous Month:
Find Last Day of Previous Month:
Find First Day of Current Month:
Find Last Day of Current Month:
我对 SSRS 不熟悉,但是您可以使用
DateTime
构造函数在 VB.Net 中获取上个月的开始和结束时间,如下所示:(yourDate
可以是任何DateTime
对象,例如DateTime.Today
或#12/23/2003#
)I'm not familiar with SSRS, but you can get the beginning and end of the previous month in VB.Net using the
DateTime
constructor, like this:(
yourDate
can be anyDateTime
object, such asDateTime.Today
or#12/23/2003#
)在 C# 中:
in C#:
我在将实际 VB.NET 转换为 SSRS 使用的表达式子集时遇到了一些困难。不过,你确实启发了我,这就是我的想法。
我知道 StartDate (上个月的第一天)有点递归。我在这里缺少什么吗?这些是严格的日期字段(即没有时间),但我认为这应该捕获闰年等。
我是怎么做的?
I was having some difficulty translating actual VB.NET to the Expression subset that SSRS uses. You definitely inspired me though and this is what I came up with.
I know it's a bit recursive for the StartDate (first day of last month). Is there anything I'm missing here? These are strictly date fields (i.e. no time), but I think this should capture leap year, etc.
How did I do?
我正在寻找一个简单的答案来自己解决这个问题。这是我发现的
这将分割年份和月份,休息一个月并得到第一天。
从当前获取上个月的第一天
更多详细信息可以在以下位置找到:
http://msdn.microsoft.com/en -us/library/aa227522%28v=vs.60%29.aspx
I was looking for a simple answer to solve this myself. here is what I found
This will split the year and month, take one month off and get the first day.
Gets the first day of the previous month from the current
More details can be found at:
http://msdn.microsoft.com/en-us/library/aa227522%28v=vs.60%29.aspx
这一个会给你日期而不是时间:
这个会给你日期时间:
This one will give you date no time:
This one will give you datetime: