S
Sean Howard
OK, here goes,
I have to create a function in Excel that shows a date string of the
format "TLyyyymmww" based on the following parameters :
a) "ww" is the week number of the week of that date, all weeks begin on
a Sunday
b) "mm" is the month number of the week described in a)
c) "yyy" is the year number of the week described in a)
What I do not understand is why must I trap the occurance of
"30-Dec-2007". If I do not then then answer will be "TL2007.12.53"
instead of "TL2008.01.01". I know this date does not work correctly but
wondered if anyone knew WHY it must be trapped. and if there anr any
other possible dated that will yield the same error
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function TILPeriod(xDate As Date) As String
Dim d As Date, w As Integer, y As Integer, m As Integer
d = Int((xDate - vbSunday) / 7) * 7 + vbSunday
w = Format(xDate, "ww", vbSunday, vbFirstFourDays)
y = Year(d)
m = Month(d)
' in case this December week should be
'moved to January next year
If (w = 1) And (m = 12) Then
m = 1
y = y + 1
'WHY !!!!!!!!!!!!!!!!!
ElseIf (d = #12/30/2007#) Then
w = 1
m = 1
y = y + 1
End If
TILPeriod = "TL" & y & "." & Format(m, "00") & "." & Format(w, "00")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Clear as mud I suppose, but I do not know if this is a coding or
mathematical problem, and any help yould be great
Sean
"Just press the off switch, and go to sleep!"
I have to create a function in Excel that shows a date string of the
format "TLyyyymmww" based on the following parameters :
a) "ww" is the week number of the week of that date, all weeks begin on
a Sunday
b) "mm" is the month number of the week described in a)
c) "yyy" is the year number of the week described in a)
What I do not understand is why must I trap the occurance of
"30-Dec-2007". If I do not then then answer will be "TL2007.12.53"
instead of "TL2008.01.01". I know this date does not work correctly but
wondered if anyone knew WHY it must be trapped. and if there anr any
other possible dated that will yield the same error
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function TILPeriod(xDate As Date) As String
Dim d As Date, w As Integer, y As Integer, m As Integer
d = Int((xDate - vbSunday) / 7) * 7 + vbSunday
w = Format(xDate, "ww", vbSunday, vbFirstFourDays)
y = Year(d)
m = Month(d)
' in case this December week should be
'moved to January next year
If (w = 1) And (m = 12) Then
m = 1
y = y + 1
'WHY !!!!!!!!!!!!!!!!!
ElseIf (d = #12/30/2007#) Then
w = 1
m = 1
y = y + 1
End If
TILPeriod = "TL" & y & "." & Format(m, "00") & "." & Format(w, "00")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Clear as mud I suppose, but I do not know if this is a coding or
mathematical problem, and any help yould be great
Sean
"Just press the off switch, and go to sleep!"