Fw: [PHP] Difference between 2 Dates

From: Date: Fri, 13 Dec 2002 19:53:58 +0000
Subject: Fw: [PHP] Difference between 2 Dates
Groups: php.general 
Request: Send a blank email to php-general+get-128206@lists.php.net to get a copy of this message
Oh dear. In what format are you storing the date in your database? If you can convert what you have into UNIX EPOCH then you can simply subtract your date against mktime(); then echo the result through getdate() and be done with it in three lines of code. -Kevin ----- Original Message ----- From: "vernon" <vernon@comp-wiz.com> To: <php-general@lists.php.net> Sent: Friday, December 13, 2002 12:43 PM Subject: [PHP] Difference between 2 Dates > I found this code on the php.net web site but am new to php and can't figure > out how to dispaly the difference once calucuated. Belowis the code I'm > using: > > # --- Date Difference --- > #Date 1 from MySQL database recordset row > $date1 = $row_rsMESSAGES['privmsgs_date']; > #Date 2 - now > $date2 = date("ymd H:is"); > > #function > function date_diff($date1, $date2) { > $s = strtotime($date2)-strtotime($date1); > $d = intval($s/86400); > $s -= $d*86400; > $h = intval($s/3600); > $s -= $h*3600; > $m = intval($s/60); > $s -= $m*60; > return > array("d"=>$d,"h"=>$h,"m"=>$m,"s"=>$s); > } > > #what I thought would dispaly the diffence but returns and error. > echo date_diff("$m, $d, $h, $m"); > > > Thanks > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#128206) next »