例如
月是’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') 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提示符下按是),或
>一周中每天的一个月天数(在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 SubIf lngCheck = vbYes Then'Option 1 one daylngDay = vbFrIDaystrOut = strOut & DaysInMonth(lngDay,strMonth) & vbNewlineElse'Option 2 all daysFor lngDay = vbSunday To vbSaturdaystrOut = strOut & DaysInMonth(lngDay,strMonth) & vbNewlineNextEnd IfMsgBox strOutEnd SubFunction DaysInMonth(ByVal lngDay,ByVal strMonth)Dim dtStart As DateDim dtEnd As DateDim dtTest As DateDim lngCnt As LongDim i As LongdtStart = DateValue(strMonth)dtEnd = DateAdd("d",strMonth,strMonth) - 1),dtStart)lngCnt = (dtEnd - dtStart + 1)DaysInMonth = Weekdayname(lngDay,vbSunday) & " - 4"For i = 1 To lngCnt Mod 7If Weekday(DateAdd("d",i - 1,dtStart)) = lngDay Then DaysInMonth = Weekdayname(lngDay,vbSunday) & " - 5"Exit ForEnd IfNextEnd Function总结
以上是内存溢出为你收集整理的如何获得一个月的总日数全部内容,希望文章能够帮你解决如何获得一个月的总日数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)