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

时间:2013-07-13 16:44:16

标签: 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
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. ..

我有办法做到这一点吗?

1 个答案:

答案 0 :(得分:0)

未经测试。可以改进。根据您的要求调整代码。

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