在Visual Basic中计算两个日期之间的工作日数
我是一名 SQL 人员,但我需要一个函数来计算 VB.NET 中两个日期之间的工作日数。我不需要担心假期。不幸的是我的尝试是徒劳的。非常感谢
这将进入 Reporting Service 2008 R2 中的自定义代码。
I'm a SQL guy, but I need a function to calculate the number of weekdays between two dates in VB.NET. I don't need to worry about holidays. My attempts unfortunately have been futile. Much appreciated
This will go in custom code in Reporting Service 2008 R2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
试试这个。我修改了我一直在使用的现有函数。这将在 SSRS 2008 中工作。请注意,如果您对此更熟悉,您也可以用 C# 编写代码,并且在部署之后,只需引用报告中的程序集即可。1
Try this. I modified an existing function that I've been using. This will work in SSRS 2008. Note, that you can also write your code in C#, if you're more comfortable with that, and after deploying it, just reference the assembly from the report.1
您不需要检查这些日期之间的每一天是否是工作日。
如果有
n
天,则有int(n / 7)
完整周,每周包含 5 个工作日,因此为5 * int(n / 7)工作日。
然后,您需要检查剩余部分周的天数(0..6 天)。
You don't need to check whether every single day between those dates is a weekday.
If there are
n
days, then there areint(n / 7)
complete weeks, each containing 5 weekdays, so that's5 * int(n / 7)
weekdays.You then need to check the days of the remaining partial week (0..6 days).
“这是我的版本 vb.net 2013,它可以工作
”谢谢 Gabe
'This is my version vb.net 2013 and its works
'Thanks Gabe
这可能会帮助其他人寻找这个。该函数不会日复一日地循环。
This may help someone else looking for this. This function doesn't loop day by day.
我有一个表达式可以计算两个日期之间一周中特定日期的数量。因此,如果您在周一、周二...周五添加金额,您将得到工作日的金额。
[DayofWeek] 是代表一天的整数:
1 - 星期日; 2 - 星期一
因此,计算
dteStartDateTime
和dteEndDateTime
之间星期一数量的表达式为:I have an expression that will calculate amount of specific day of week between two dates. So if you add amount on Mondays, Tuesdays ... Fridays you will get the amount of week days.
[DayofWeek] is an integer representing a day:
1 - Sunday; 2 - Monday
So an expression that will calculate amount of Mondays between
dteStartDateTime
anddteEndDateTime
is:我认为这可能会有所帮助
在这里,我返回了“wkend”,它是函数中变量的周末部分。或者,您可以将返回值更改为“wkday”,即所选日期之间的工作日数。
我希望这有帮助。不过它对我有用
I think this may help
Here, i returned "wkend" which is the weekend part of the variables in the function. Alternatively, you can change the returned value to "wkday" which is the number of weekdays between the selected dates.
I hope this helps. It works for me though