1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
# ($year,$month,$day) = Add_Delta_Days($year,$month,$day, $Dd);
This function has two principal uses:
First, it can be used to calculate a new date, given an initial date and an offset (which may be positive or negative) in days, in order to answer questions like "today plus 90 days -- which date gives that?".
(In order to add a weeks offset, simply multiply the weeks offset with "7" and use that as your days offset.)
Second, it can be used to convert the canonical representation of a date, i.e., the number of that day (where counting starts at the 1st of January in 1 A.D.), back into a date given as year, month and day.
Because counting starts at "1", you will actually have to subtract "1" from the canonical date in order to get back the original date:
$canonical = Date_to_Days($year,$month,$day);
($year,$month,$day) = Add_Delta_Days(1,1,1, $canonical - 1);
Moreover, this function is the inverse of the function "Delta_Days()":
Add_Delta_Days(@date1, Delta_Days(@date1, @date2))
yields "@date2" again, whereas
Add_Delta_Days(@date2, -Delta_Days(@date1, @date2))
yields "@date1", and
Delta_Days(@date1, Add_Delta_Days(@date1, $delta))
yields "$delta" again. |
Partager