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:
» Tr Trageting In Javascript PLEASE HELP!!!!
» How Do I Create A Cronjob On A Linux Server?
» In What Ways Is PHP 5 Better Than PHP 4?
» I Am Doing PHP Mysql But I Dont Know Any Programming Language Kindly Advice I Already Paid For That Course
» How I Can Pick System Date In Php? Is There Any Function For This
» How Can I Print In PHP?
» Smap Schema
» I Want To Display Items From Mysql In A Combo/list Box And Select Mulitple Items And Send Values To Database


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!