Solved

PHP subtracting dates

Posted on 2011-03-20
2
426 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

837 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