Purpose We want to determine the first and the last day of the current, next or previous month. This is useful, for example, for reporting purposes where you need to select the right time interval |
We use GuiXT string and date operations: // Determine first and last day of this month /next month /previous month Set V[k] 1 // 1=next month, 0=this month, -1=previous month
Set V[M] "&V[today_M]" Set V[Y] "&V[today_Y]"
Set V[M] "&V[M]" + &V[k] if V[M=13] Set V[M] "01" Set V[Y] &V[Y] + 1 else if V[M=0] Set V[M] "12" Set V[Y] &V[Y] - 1 endif endif
Set V[M](1-2) "0&V[M]" -alignRight
Set V[from] "01.&V[M].&V[Y]"
// build first day of next month then subtract 1 day Set V[M] "&V[M]" + 1 if V[M=13] Set V[M] "01" Set V[Y] &V[Y] + 1 endif
Set V[M](1-2) "0&V[M]" -alignRight Set V[to] "01.&V[M].&V[Y]" Set V[to] "&V[to]" - 1
// of this/next/previous month // Optionally: // if necessary change the dates from format dd.mm.yyyy to correct user format // Attention: in this case a valid RFC user/password is needed in GuiXT profile Set V[diff] "&V[from]" - "&V[today_d.m.y]" Set V[from] "&V[today+&V[diff]_user]" Set V[diff] "&V[to]" - "&V[today_d.m.y]"
Set
V[to]
"&V[today+&V[diff]_user]" |
Components |