# An easy Question should mean an easy answer

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on

I am only asking for my code to do a simple thing but for some reason i
just can't get it to do what i want it to do... it been bugging me all
day!

The user inputs 2 dates on one page. in the form xx/xx/xxxx
I then want the output page to display the amount of days that there
are between these two dates, inclusive. For example:

01/01/2005
03/01/2005
= 3 days

Also over a month change..

27/03/2005
02/04/2005
= 7 days

I can't see anywhere on the forum a successfull version of this in PHP
code.

Thanks
Ben

## Re: An easy Question should mean an easy answer

http://www.phpclasses.org/discuss/package/2180 / ?

## Re: An easy Question should mean an easy answer

Sorry, as you may well tell i am a newbee.
is ther eanywhere i can get instructions on what to do with this file?
wher eis the location it needs to go and how do i call it?

Thanks for this help

## Re: An easy Question should mean an easy answer

ben3003 wrote:

Actually, this would be 60 days; 03/01 would be interpreter
as March 1, not January 3...

Anyway, here's what you need:

\$date1 = '01/01/2005';
\$date1 = '03/01/2005';
\$days = round((strtotime("\$date2 23:59:59") -
strtotime("\$date1 00:00:00")) / (24*60*60));

Cheers,
NC

## Re: An easy Question should mean an easy answer

Convert the two dates to a unix timestamp, subtract them, and you'll get
your answers in seconds. As long as both dates are after 1969, you'll be
fine.

-Joe

## Re: An easy Question should mean an easy answer

ben3003 wrote:

The complexity of a question is in no way related to how succinctly you
can state the question!

compare:
"Why do we think gravitation and acceleration are equivelant?"

with:

"What is 89 plus 5?"

Finding the difference between dates isn't trivial, although it is a

## Re: An easy Question should mean an easy answer

Check out www.phpclasses.org.  A search on 'compare date' turns up a number of
classes that accomplish this sort of thing.

HTH