You are right, I've corrected the code. This must work in case year has 53 weeks.
Regards,
Walter Herdes
=======================================================================
NAMED ER: Get Number Of the Week
=======================================================================
evt_jdDate_DTE
evt_mnDayOfWeekA_DOW
evt_mnDtMatchCkOrItemCtry_DTMx
evt_mnDtMatchCkOrItemYr_DTMY
evt_mnElapsedDays_EDAYS
evt_mnDayOfWeekAJanuary1st_DOW
0001 If BF cMode is not equal to "1"
0002 BF mnCenturyYear = date_year([BF jdDate])
0003 End If
0004 VA evt_mnDtMatchCkOrItemYr_DTMY = mod([BF mnCenturyYear],100)
0005 VA evt_mnDtMatchCkOrItemCtry_DTMx = ([BF mnCenturyYear]-[VA
evt_mnDtMatchCkOrItemYr_DTMY])/100
0006 User Date, Format
"1" -> mnMonth
"1" -> mnDay
VA evt_mnDtMatchCkOrItemYr_DTMY -> mnYear
VA evt_mnDtMatchCkOrItemCtry_DTMx -> mnCentury
VA evt_jdDate_DTE <- jdReturnDate
"<Blank>" -> cProcessingFlag
0007 Get The Day Of The Week - 0 = Sunday, 6 = Saturday
VA evt_jdDate_DTE -> jdDate
VA evt_mnDayOfWeekAJanuary1st_DOW <- mnDayofWeekA
UNDEFINED <- cErrorCode
0008 If VA evt_mnDayOfWeekAJanuary1st_DOW is equal to <Zero>
0009 VA evt_mnDayOfWeekA_DOW = "7"
0010 Else
0011 VA evt_mnDayOfWeekA_DOW = VA evt_mnDayOfWeekAJanuary1st_DOW
0012 End If
0013 If VA evt_mnDayOfWeekA_DOW is greater than "4"
0014 VA evt_jdDate_DTE = add_days([VA evt_jdDate_DTE],8-[VA evt_mnDayOfWeekA_DOW])
0015 Else
0016 If VA evt_mnDayOfWeekA_DOW is not equal to "1"
0017 VA evt_jdDate_DTE = add_days([VA evt_jdDate_DTE],1-[VA evt_mnDayOfWeekA_DOW])
0018 End If
0019 End If
0020 If BF cMode is not equal to "1"
0021 VA evt_mnElapsedDays_EDAYS = days_between([VA evt_jdDate_DTE],[BF jdDate])
0022 BF mnWeekNumber = floor([VA evt_mnElapsedDays_EDAYS]/7+1)
0023 BF mnDayofWeekA = mod([VA evt_mnElapsedDays_EDAYS]-[VA
evt_mnDayOfWeekAJanuary1st_DOW]+14,7)
0024 If BF mnWeekNumber is equal to "53"
0025 VA evt_mnElapsedDays_EDAYS = mod([VA evt_mnDtMatchCkOrItemYr_DTMY],4)
0026 If VA evt_mnElapsedDays_EDAYS is not equal to <Zero>
0027 VA evt_mnDayOfWeekA_DOW = [VA evt_mnDayOfWeekA_DOW]+1
0028 Else
0029 VA evt_mnDayOfWeekA_DOW = [VA evt_mnDayOfWeekA_DOW]+2
0030 End If
0031 If VA evt_mnDayOfWeekA_DOW is greater than "7"
0032 VA evt_mnDayOfWeekA_DOW = [VA evt_mnDayOfWeekA_DOW]-7
0033 End If
0034 If VA evt_mnDayOfWeekA_DOW is less than "5"
0035 BF mnCenturyYear = [BF mnCenturyYear]+1
0036 BF mnWeekNumber = "1"
0037 End If
0038 Else
0039 If BF mnWeekNumber is equal to <Zero>
0040 BF mnCenturyYear = [BF mnCenturyYear]-1
0041 VA evt_mnDtMatchCkOrItemYr_DTMY = mod([BF mnCenturyYear],100)
0042 VA evt_mnDtMatchCkOrItemCtry_DTMx = ([BF mnCenturyYear]-[VA
evt_mnDtMatchCkOrItemYr_DTMY])/100
0043 VA evt_mnElapsedDays_EDAYS = mod([VA evt_mnDtMatchCkOrItemYr_DTMY],4)
0044 If VA evt_mnElapsedDays_EDAYS is not equal to <Zero>
0045 VA evt_mnDayOfWeekA_DOW = [VA evt_mnDayOfWeekA_DOW]-1
0046 Else
0047 VA evt_mnElapsedDays_EDAYS = mod([VA evt_mnDtMatchCkOrItemCtry_DTMx],4)
0048 If VA evt_mnElapsedDays_EDAYS is not equal to <Zero>
0049 VA evt_mnDayOfWeekA_DOW = [VA evt_mnDayOfWeekA_DOW]-1
0050 Else
0051 VA evt_mnDayOfWeekA_DOW = [VA evt_mnDayOfWeekA_DOW]-2
0052 End If
0053 End If
0054 If VA evt_mnDayOfWeekA_DOW is less than "1"
0055 VA evt_mnDayOfWeekA_DOW = [VA evt_mnDayOfWeekA_DOW]+7
0056 End If
0057 If VA evt_mnDayOfWeekA_DOW is greater than "4"
0058 BF mnWeekNumber = "52"
0059 Else
0060 BF mnWeekNumber = "53"
0061 End If
0062 End If
0063 End If
0064 Else
0065 If BF mnDayofWeekA is equal to <Zero>
0066 VA evt_mnElapsedDays_EDAYS = [BF mnWeekNumber]*7
0067 Else
0068 VA evt_mnElapsedDays_EDAYS = ([BF mnWeekNumber]-1)*7+[BF mnDayofWeekA]
0069 End If
0070 BF jdDate = add_days([VA evt_jdDate_DTE],[VA evt_mnElapsedDays_EDAYS]-1)
0071 End If
B7332 / XE / NT4 / SQL 7 / VisualStudio 6 SP5