如何获得一个月的总日数
发布时间:2020-12-17 07:15:12 所属栏目:百科 来源:网络整理
导读:我希望按天计算每月总天数. 例如 月是’01 / 2011′(mm / yyyy) Expected OutputSunday - 5Monday - 5Tuesday - 5Wednesday - 4Thursday - 4Friday - 4Saturday - 4 试过的代码 Dim lngCnt As Long Dim strOut As String dtStart = DateValue('01/2012') dtE
我希望按天计算每月总天数.
例如 月是’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 上述代码将给出结果为星期三= 4,11,18,25 但我希望像这样的周三= 4’的总数 如何在vb6中完成 需要VB6代码帮助 解决方法
更新的答案
更新了您的评论以返回 >仅限一天的一个月中的天数(在Msgbox提示符下按是),或 Sub GetDay() Dim strMonth As String Dim strOut As String Dim lngDay As Long Dim lngCheck As Long strMonth = "01/2012" lngCheck = MsgBox("Press Yes to run single day" & vbNewLine & "Press No to run the entire week",vbYesNoCancel,"User choice") If lngCheck = vbCancel Then Exit Sub If lngCheck = vbYes Then 'Option 1 one day lngDay = vbFriday strOut = strOut & DaysInMonth(lngDay,strMonth) & vbNewLine Else 'Option 2 all days For lngDay = vbSunday To vbSaturday strOut = strOut & DaysInMonth(lngDay,strMonth) & vbNewLine Next End If MsgBox strOut End Sub Function DaysInMonth(ByVal lngDay,ByVal strMonth) Dim dtStart As Date Dim dtEnd As Date Dim dtTest As Date Dim lngCnt As Long Dim i As Long dtStart = DateValue(strMonth) dtEnd = DateAdd("d",strMonth,strMonth) - 1),dtStart) lngCnt = (dtEnd - dtStart + 1) DaysInMonth = WeekdayName(lngDay,vbSunday) & " - 4" For i = 1 To lngCnt Mod 7 If Weekday(DateAdd("d",i - 1,dtStart)) = lngDay Then DaysInMonth = WeekdayName(lngDay,vbSunday) & " - 5" Exit For End If Next End Function (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |