Could I ask a related question? I am trying to calculate the last day of a given month, based on the first day of that month (to eliminate the user from having to enter 2 date fields). For example, if the user enters "12/01/09" as the starting date, I would like to calculate "12/31/09" as the ending date. I can accurately calculate the last day of the current month, but can't seem to calculate the last day of other months. Does you have any suggestions? (All my attempts are below).
CLEAR
ld_DOM_first = {^2009-12-01}
?"------------------------------"
?"If the value of 'ld_DOM_first' is '12/01/09' then I need the value of 'ld_DOM_last' to be '12/31/09'"
?"------------------------------"
?"ld_DOM_first= " + DTOC(ld_DOM_first)
?
?"The following is on the right track. It shows the last day of the month, but I need the last day of 'ld_DOM_first':"
ld_DOM_last = GOMONTH(DATE() - DAY(DATE()) - 0, 1) && 08/31/11
?"0 DOM_last (current month)= " + DTOC(ld_DOM_last)
?
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) -0, -1) && 10/30/09
?"1 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) -0, -0) && 11/30/09
?"2 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) -0, +1) && 12/30/09
?"3 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) +1, -1) && 11/01/09
?"4 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) +1, -0) && 12/01/09
?"5 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) +1, +1) && 01/01/10
?"6 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) -1, -1) && 10/29/09
?"7 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) -1, -0) && 11/29/09
?"8 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first) -1, +1) && 12/29/10
?"9 DOM_last= " + DTOC(ld_DOM_last)
?"------------"
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first -1 ) -0, -1) && 10/01/09
?"11 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first -2 ) -0, -0) && 11/02/09
?"12 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first +1 ) -0, +1) && 12/29/09
?"13 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first -1 ) -1, -1) && 09/30/09
?"14 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first -2 ) -1, -0) && 11/01/09
?"15 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first +1 ) -1, +1) && 12/28/09
?"16 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first -1 ) +1, -1) && 10/02/09
?"17 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first -2 ) +1, -0) && 11/03/09
?"18 DOM_last= " + DTOC(ld_DOM_last)
ld_DOM_last = GOMONTH(ld_DOM_first - DAY(ld_DOM_first +1 ) +1, +1) && 12/30/09
?"19 DOM_last= " + DTOC(ld_DOM_last)
?"------------------------------"
?
RETURN