当月的第一天和最后一天

发布于 2024-12-11 00:12:28 字数 198 浏览 0 评论 0原文

在 SQL Server 报告服务中;如何计算上个月的第一天和最后一天?

我知道我可以使用下面的表达式来获取当月的最后一天,但在尝试查找上个月的第一天和最后一天时我陷入了困境。

=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(1).AddDays(-1)

In SQL Server Reporting Services; How can I calculate the first and last day of the previous month?

I know I can use the expression below to get the last day of the current month, but I'm stuck when trying to find the first and last of the previous month.

=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(1).AddDays(-1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

神爱温柔 2024-12-18 00:12:28

只是根据您的代码工作进行的猜测。

--previous month last
=DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)

--previous month first
=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(-1)

Just a guess based on your code working.

--previous month last
=DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)

--previous month first
=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(-1)
哽咽笑 2024-12-18 00:12:28

本月第一天:
=dateadd("m",0,dateserial(年(今天),月(今天),1))

本月最后一天:
=dateadd("m",1,dateserial(年(今天),月(今天),0))

上个月的第一天:
=dateadd("m",-1,dateserial(年(今天),月(今天),1))

下个月的第一天:
=dateadd("m",1,dateserial(年(今天),月(今天),1))

上个月的最后一天:
=dateadd("m",0,dateserial(年(今天),月(今天),0))

下个月的最后一天:
=dateadd("m",2,dateserial(年(今天),月(今天),0))

First day of this month:
=dateadd("m",0,dateserial(year(Today),month(Today),1))

Last day of this month:
=dateadd("m",1,dateserial(year(Today),month(Today),0))

First day of last month:
=dateadd("m",-1,dateserial(year(Today),month(Today),1))

First day of next month:
=dateadd("m",1,dateserial(year(Today),month(Today),1))

Last day of last month:
=dateadd("m",0,dateserial(year(Today),month(Today),0))

Last day of next month:
=dateadd("m",2,dateserial(year(Today),month(Today),0))

愁以何悠 2024-12-18 00:12:28

对于当前月份

 =DateSerial(Year(Parameters!ParameterName.Value), Month(Parameters!ParameterName.Value), "1").AddMonths(1).AddDays(-1)

上个月最后一天:

=DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)

上个月第一天:

=DateSerial(Year(Parameters!ParameterName.Value), Month(Parameters!ParameterName.Value), "1").AddMonths(-1)

For current month

 =DateSerial(Year(Parameters!ParameterName.Value), Month(Parameters!ParameterName.Value), "1").AddMonths(1).AddDays(-1)

Previous month last day:

=DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)

Previous month first day:

=DateSerial(Year(Parameters!ParameterName.Value), Month(Parameters!ParameterName.Value), "1").AddMonths(-1)
桃酥萝莉 2024-12-18 00:12:28

上个月最后日期:

=DateAdd("d",-(Day(today)), Today)

Previous month last date:

=DateAdd("d",-(Day(today)), Today)
末が日狂欢 2024-12-18 00:12:28

上个月第一天:

=DateAdd("m",-1,DateAdd("d",1-(Day(Today)), Today))

First of previous month:

=DateAdd("m",-1,DateAdd("d",1-(Day(Today)), Today))
风筝在阴天搁浅。 2024-12-18 00:12:28
=DateSerial(Year(Now), Month(Now), 1) for first day of the month 

=DateSerial(Year(Now), Month(Now)+1, 0) for the last day of the month.

http://www.answermysearches.com/ssrs-how-to-set-a-default-parameter-to-the-first-day-of-the-month/2167/

=DateSerial(Year(Now), Month(Now), 1) for first day of the month 

and

=DateSerial(Year(Now), Month(Now)+1, 0) for the last day of the month.

http://www.answermysearches.com/ssrs-how-to-set-a-default-parameter-to-the-first-day-of-the-month/2167/

醉城メ夜风 2024-12-18 00:12:28

使用本机 VB 函数

上个月的第一天

=DateAdd("m", -1, DateSerial(Year(Today()), Month(Today()), 1))

上个月的最后一天

=DateAdd("d", -1, DateSerial(Year(Today()), Month(Today()), 1))

Using Native VB Functions

First Day of Previous Month

=DateAdd("m", -1, DateSerial(Year(Today()), Month(Today()), 1))

Last Day of Previous Month

=DateAdd("d", -1, DateSerial(Year(Today()), Month(Today()), 1))
深巷少女 2024-12-18 00:12:28

我能够完成此任务,并通过使用以下命令以 mm/dd 格式显示它:

=Format(DateAdd("D", -1, (DateAdd("M", 1, yourdate.value))), "MM/dd")

I was able to accomplish this, and show it in mm/dd format by using:

=Format(DateAdd("D", -1, (DateAdd("M", 1, yourdate.value))), "MM/dd")
望喜 2024-12-18 00:12:28
=DateSerial(Year(Now), Month(Now), 1)
=DateSerial(Year(Now), Month(Now), 1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文