English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can anybody help me in count the number of night for guests stay? Example arrival date is 28-09-2006 and departure date is 30-09-2006. That means this guest is staying for 2 nights. I doing mktime() izit correct? My coding is:

$first_date_ex = explode("-",$arrive);
$second_date_ex = explode("-",$depa);
// makes the dates and times into unix timestamps.
$first_unix = mktime($first_date_ex[1], $first_date_ex[2], $first_date_ex[0]);
$second_unix = mktime($second_date_ex[1], $second_date_ex[2], $second_date_ex[0]);

// Gets the difference between the two unix timestamps.
$timediff = $second_unix-$first_unix;

$days=intval($timediff/86400);
$remain=$timediff%86400;
echo $days;

but when i echo $days, i get value "0". why? my coding correct or not?

2006-08-16 20:44:26 · 2 answers · asked by 183 1 in Computers & Internet Programming & Design

2 answers

Just Try it this way
$datet = getdate(strtotime("2006-08-08")); // or date("Y-m-d")
$datey = getdate(strtotime("2006-08-09"));
$t=$datey['yday']-$datet['yday']; // between my two dates is '1' day
echo $t;
?>

Helmut

2006-08-16 21:56:38 · answer #1 · answered by hswes 2 · 0 0

In personal abode web page language i am going to't inform you. In an MS get admission to Database, (reminiscent of sq. language) in question layout you create a field with good right here administration: =[Departure Date field]-[Arrival Date field]

2016-11-05 00:05:18 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers