Solved

PHP subtracting dates

Posted on 2011-03-20
2
433 Views
Last Modified: 2012-05-11
Hi experts,

I have 2 dates (arrival and departure). I want to work up the number of nights stayed based on those 2 dates. How can I achieve this. So far I have....

 $Arrival_Date = date("Y-m-d", strtotime($Arrival_Date));
$Departure_Date = date("Y-m-d", strtotime($Departure_Date));

$NoNights = $Departure_Date - $Arrival_Date;

But this returns zero.

Many Thanks,
Dean
0
Comment
Question by:deanlee17
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35175082
date() returns a string, not a number (neither a date).

what about:
$Arrival_Date = strtotime($Arrival_Date);
$Departure_Date = strtotime($Departure_Date);

$NoNights = $Departure_Date - $Arrival_Date;

Open in new window

0
 

Author Comment

by:deanlee17
ID: 35175102
Excellent, I added ' / 86400 ' and it did the job.

Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question