Purpose Determine the week for a given date
For a given date you want
to determine the week 1...53 and the year corresponding to this
week. The date is specified in one of the external date formats
(like dd.mm.yyyy or mm/dd/yyyy). |
Solution 1 (Function call)
// sample value // use date calculations to force
format YYYYMMDD Set V[d] "01.01.1900" + "&V[diff]" Set V[yyyymmdd] "&V[d](7-10)&V[d](4-5)&V[d](1-2)" // Determine week Set V[year] "&V[yearweek](1-4)"Set V[week] "&V[yearweek](5-6)" Message "&V[mydate] is in week &V[week] of the year &V[year]" |
Sample
message 1
|
Solution 2 (Date calculations)
// sample value // Get date in format dd.mm.yyyy, to avoid handling all different
date formats Set V[date] "01.01.1000" + "&V[reldate]" Set V[year] "&V[date](7-10)"label compute_week// Get start of 1st week Set V[firstweek] "&V[firstweek]" * 7 // Get week number Set V[week] "&V[week]" - "&V[firstweek]" Set V[week] "&V[week]" + 4 Set V[week] "&V[week]" / 7 decimals=0 // Last week of previous year? (can be 52 or 53) Set V[year] "&V[year]" - 1 Set V[date] "31.12.&V[year]" goto compute_week endif // ... or first week of following year? Set V[lastweek] "&V[firstweek]" + 364 if V[lastweek>28.12.&V[year]] Set V[year] "&V[year]" + 1 Set V[week] 1 endif endif Message "&V[mydate] is in week &V[week] of the year &V[year]" |
Sample
message 2
|
Components |