Again the solution is to convert the dates into timestamps for easy
comparison.  In your case you can use the strtotime() function.  I believe
that yyyy-mm-dd is a standard date format that the function will recognize,
is it not?

$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
if ($ts1 > $ts2)
{
   // .. blah blah blah.
}

-Kevin


----- Original Message -----
From: "Colin Bossen" <[EMAIL PROTECTED]>
To: "vernon" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, December 13, 2002 2:50 PM
Subject: Re: [PHP] Difference between 2 Dates


> I have a similar problem. I am trying to figure out which of two dates
> is greater. Both are in the yyyy-mm-dd format. Is there any easy
> function that allows this sort of comparison or am I missing something?
>
>
> On Friday, December 13, 2002, at 01:43 PM, vernon wrote:
>
> > 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
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to