Solved

PHP subtracting dates

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now