PHP booking system - calculate the time giving the wrong result

Im working on a uni project for a simple car rental system. My problem arises when calculating the time (number of days and hours for car rental).

Now is the time (where am I) 12:15 pm

CODE:

        //Test Variables
         $ciDate = '2016-08-28';
         $ciTime = '13:10';

        //calc Time
        $calcDate = $ciDate.$ciTime;        
        $calcDate =  strtotime($calcDate);
        $remaining = $calcDate - time();
        $days_remaining = floor($remaining / 86400);
        $hours_remaining = floor(($remaining % 86400) / 3600);
        $totPrice = $days_remaining * 4;
        //Disp Result
        echo $days_remaining. ' Days and ' . $hours_remaining. ' hours';

MY PROBLEM

When the above code is executed, I will return 2 days and 5 hours , which is wrong, given that my time is now 12:15 PM 2016/08/26

I'm going to go on a limb here and guess the problem is that the server time is different from my current time?

Any suggestions on how to fix the above problem are greatly appreciated.

EDIT:

At the time of writing, the correct result should be 2 days and 1 hour

+4
source share
1

, , , .
, code.

date_default_timezone_set ( string $timezone_identifier );

, ,

date_default_timezone_set("Asia/Baghdad");

.

http://php.net/manual/en/timezones.asia.php

+3

Source: https://habr.com/ru/post/1652554/


All Articles