Vb6 “如何创建标题”;“每周的日期范围”;在Flexgrid中

Vb6 “如何创建标题”;“每周的日期范围”;在Flexgrid中,vb6,c1flexgrid,Vb6,C1flexgrid,帮助我使用“C1 FlexGrid”解决Visual Basic编码的问题 如何获得显示周数的日期范围 例如: January 2003 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 我想展示一下 01/01/03 - 04/01/03 as "week 1" of January 03 0

帮助我使用“C1 FlexGrid”解决Visual Basic编码的问题

如何获得显示周数的日期范围

例如:

   January 2003
 S  M Tu  W Th  F  S
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
我想展示一下

01/01/03 - 04/01/03 as "week 1" of January 03
01/05/03 - 01/11/03 as "week 2" of January 03
01/12/03 - 18/01/03 as "week 3" in January 03 ... up "week 5", etc. ..

有什么方法可以做到这一点吗?

未经测试。改进是可能的。根据您的要求对代码进行调整

Public Function DateOfFirstDayofWeek(intCurrentDayofWeek As Integer, WhichDate As Date) As Date
    DateOfFirstDayofWeek = DateAdd("D", intCurrentDayofWeek * (-1) + 2, WhichDate)
End Function

Function dhFirstDayInMonth(dtmDate As Date) As Date
    dhFirstDayInMonth = DateSerial(year(dtmDate), Month(dtmDate), 1)
End Function

Function dhLastDayInMonth(dtmDate As Date) As Date
    dhLastDayInMonth = DateSerial(year(dtmDate), Month(dtmDate) + 1, 0)
End Function

Private Sub getWeekRange_Click()
Dim startDate As Date
Dim endDate As Date
Dim tmpDate  As Date
Dim dateOfMonth As Date
Dim myDate As Date

dateOfMonth = CDate("01/02/2013") 
endDate = dhLastDayInMonth(dateOfMonth)
startDate = dhFirstDayInMonth(dateOfMonth)
tmpDate = startDate

While tmpDate < endDate
    myDate = DateOfFirstDayofWeek(Weekday(tmpDate, vbSunday), tmpDate) ''Assuming Week starts with Sunday
    tmpDate = DateAdd("d", 6, myDate)
    If myDate < startDate Then
        myDate = startDate
    ElseIf tmpDate > endDate Then
        tmpDate = endDate
    End If
    Debug.Print myDate & "      " & tmpDate 'This Prints the Start date and End date of every week
Wend
End Sub
公共函数DateOfFirstDayofWeek(intCurrentDayofWeek为整数,WhichDate为日期)为日期
DateOfFirstDayofWeek=DateAdd(“D”,intCurrentDayofWeek*(-1)+2,WhichDate)
端函数
函数dhFirstDayInMonth(dtmDate作为日期)作为日期
dhFirstDayInMonth=日期序列(年(dtmDate),月(dtmDate),1)
端函数
函数dhLastDayInMonth(dtmDate作为日期)作为日期
dhLastDayInMonth=DateSerial(年(dtmDate),月(dtmDate)+1,0)
端函数
私有子getWeekRange_Click()
Dim startDate作为日期
Dim endDate作为日期
Dim tmpDate As Date
Dim dateOfMonth作为日期
将myDate设置为日期
月日=日期(2013年2月1日)
endDate=dhLastDayInMonth(dateOfMonth)
startDate=dhFirstDayInMonth(dateOfMonth)
tmpDate=起始日期
而tmpDateendDate然后
tmpDate=endDate
如果结束
调试。打印myDate&“&tmpDate”打印每周的开始日期和结束日期
温德
端接头

@it.bayu,你需要接受帮助你的答案。通过单击答案的向上/向下投票控件下方的勾号,可以接受答案