-2

I have 2 dates a Checkin Date and Check out Date on a booking system. i want to find out the amount of days from checkin to checkout. I can run a Select query in mysql and get my results. But i am trying to work out ho to do it easy in php.

I do not know how to display the query results in each row of the bookings

My sql query:

SELECT timestampdiff(DAY, bookeddate, bookeddateout) AS days
FROM users

this works fine and creates temp column called days.

I am newish to this and i am not sure what to do. sorry guys. Al i want is to display the days a person is staying in a column on the users table.

Blue
  • 22,608
  • 7
  • 62
  • 92
Icelander
  • 45
  • 6
  • 1
    Possible duplicate of [How to calculate the difference between two dates using PHP?](https://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php) – Dave Jul 21 '19 at 10:50

1 Answers1

0

Yo can use this function i write call as dataDiff($firstDay,$lastDay)

function dataDiff($date1, $date2) {
    $dateDiff = 0;
    $nextday = $date1;
    while($nextday <= $date2) {
        $nextday = date("Y-m-d", strtotime("+1 day", strtotime($nextday)));
        $dateDiff++;
    }
    return $dateDiff;
}