Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP subtracting dates

Posted on 2011-03-20
2
Medium Priority
?
465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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