如何获取一个月内的总天数
我想按天分组查找每月的总天数。
例如
月份是 '01/2011'
(mm/yyyy)
Expected Output
Sunday - 5
Monday - 5
Tuesday - 5
Wednesday - 4
Thursday - 4
Friday - 4
Saturday - 4
尝试的代码
Dim lngCnt As Long
Dim strOut As String
dtStart = DateValue('01/2012')
dtEnd = DateAdd("d", DateDiff("d", '01/2012', DateAdd("m", 1, '01/2012') - 1), dtStart)
lngCnt = Weekday(dtStart) - 3
Do
lngCnt = lngCnt + 3
strOut = strOut & Format(lngCnt, "00") & ","
Loop While lngCnt + 3 <= dtEnd - dtStart
上面的代码将给出结果为 Wednesday = 4, 11, 18, 25
但我想要wednesday = 4
的总数 '这样如何
在 vb6 中完成
需要 VB6 代码帮助
I want to find a total days per month group by days.
For Example
Month is '01/2011'
(mm/yyyy)
Expected Output
Sunday - 5
Monday - 5
Tuesday - 5
Wednesday - 4
Thursday - 4
Friday - 4
Saturday - 4
Tried Code
Dim lngCnt As Long
Dim strOut As String
dtStart = DateValue('01/2012')
dtEnd = DateAdd("d", DateDiff("d", '01/2012', DateAdd("m", 1, '01/2012') - 1), dtStart)
lngCnt = Weekday(dtStart) - 3
Do
lngCnt = lngCnt + 3
strOut = strOut & Format(lngCnt, "00") & ","
Loop While lngCnt + 3 <= dtEnd - dtStart
The above Code will give the result as Wednesday = 4, 11, 18, 25
But i want total count of wednesday = 4
'like this
How to accomplish in vb6
Need VB6 Code Help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个您可以调用的函数,
它需要两个参数(年和月)并返回一个数组(1 到 7),即该月中星期日到星期六的天数
更新:
使用它来获取数量一个月中的星期五,使用
更新 2:
接受 Brettdj 的建议
要返回类似“Fridays = 4”的字符串,请使用
Here's a function you can call
It takes two parameters (year and month) and returns an array (1 to 7) being Sunday to Saturday number of days in the month
UPDATE:
to use this to get number of Fridays in a month, use
Update 2:
Taking Brettdj 's advise
To return a string like "Fridays = 4" use
更新答案
已更新您的评论,以仅返回某
Yes
),或一周中的每一天返回一个月中的天数(按
No
在 Msgbox 提示符下)。Updated Answer
Updated for your comment to return either
Yes
on Msgbox prompt), orDays in a month for every day in the week (Press
No
on Msgbox prompt).