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 Do I Create My Own Facebook Application?
» How Do I Change The Color Of My Table Cell When A User Does A Mouseover?
» Using PHP How Can I Know If A User Is Logged In?
» Get A Booking Form Working In Flash: Cannot With Drop Down Boxes.
» In What Ways Is PHP 5 Better Than PHP 4?
» Need To Know How To Make A Java Program To Put Mecical Records For My Java Class
» Challenges In Porting C++ Windows To Linux Platform
» How Can I Ident The Tab For Internet Explore In The Same Session?


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!