Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtracting Dates 2

Status
Not open for further replies.

jsnull

IS-IT--Management
Feb 19, 2002
99
US
I want to be able to subtract one date from another and determine if the dates are five years or less apart using PHP using the mm/dd/yyyy format.

Please advise as to possible workable solutions, for example:

$thisdate = "05/06/2006";
$comparedate = "05/01/2001";

$difference = $thisdate - $thatdate;

If ($difference < 5){
do this
}


Jim Null
[afro]
 
How about:

Code:
$date1="05/06/2006";
$date2="05/01/2001";
$years=(strtotime($date1)-strtotime($date2))/31536000;
if ($years<5)
{
echo "Less tan five yeasr";
}

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
You are most welcome.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Similar threads

Replies
3
Views
205
Replies
12
Views
212
Replies
2
Views
74
Replies
5
Views
69

Part and Inventory Search

Sponsor

Back
Top