Solved

PHP subtracting dates

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

785 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