Get Answers!
   

Diesel

How Can I Show The Difference Between Two Dates Using PHP?

Tuesday, 21st October 2008

I need to display this as: x minutes ago x hours ago x days ago
 





Jess
Hi,
This should be just the script you are looking for:

<?php
$date1=time();
$date2=strtotime($pastdate)

$dateDiff = $date1 - $date2;
$fullDays = floor($dateDiff/(60*60*24));
$fullHours = floor(($dateDiff-($fullDays*60*60*24))/(60*60));
$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
echo "Differernce is $fullDays days, $fullHours hours and $fullMinutes minutes.";
?>
Wednesday, 22nd October 2008
Votes:

More Programming:
» How Can I Get An Interactive Coloring Book For My Website?
» How Can I Add 3 Hrs To The Current Time In PHP?
» \Java And SNA: A Case Study : Classic Transaction #5 : Source Code ?
» How Do I Get The Length Of A String In JavaScript?
» We Wish To Create A Sign In Form As Like Http://www.realtor.com/. Please Le Me Know How To Set Up Such A Form
» Get A Booking Form Working In Flash: Cannot With Drop Down Boxes.
» How Do I Set A Target For A JavaScript Link?
» How To Store Xml File In Mysql Database Using Php


Leave a Comment on "How Can I Show The Difference Between Two Dates Using PHP?"
You must be logged in to post a comment.


Link to This Question!