I have a curious problem with using unix timestamps to work out date differences.
My user need to enter a start date and number of nights (its a vacation booking system).
I need to work out the departure date by adding the number of nights to the start date.
I use code as follows:
// $arrday, $arrmonth, $arryear and $nights are entered into web form, e.g. 12, 1, 2002, 7
// 86400 = 606024 - i.e. adder for one day to unix timestamp
$arrtime = mktime(0,0,0,$arrmonth,$arrday,$arryear);
$deptime = $arrtime + ($nights * 86400);
$depday = date("j",$deptime);
$depmonth = date("n",$deptime);
$depyear = date("Y",$deptime);
For the most part this works fine. However, some date combinations result in odd answers.
For example:
$arrday 22
$arrmonth 10
$arryear 2002
$nights 3
results in
$depday 25
$depmonth 10
$depyear 2002
which is correct, but
$arrday 25
$arrmonth 10
$arryear 2002
$nights 3
results in
$depday 27
$depmonth 10
$depyear 2002
which is not. It should be 28,10,2002. This happens with 25/10/2002 to 27/10/2002. There is also a period in April when this happens and there may be more.
What am I doing wrong?
Thanks,
Cris