Re: [PHP] comparing dates works sometimes and fails another time!

2001-03-29 Thread trogers

You are doing a string compare not date, convert them to a unix time stamp 
and then compare

$d1 = explode("-",$date1);
$d2 = explode("-",$date2);
$ts1 = mktime(0,0,0,$d1[1],$d1[2],$d1[0]);
$ts2 = mktime(0,0,0,$d2[1],$d2[2],$d2[0]);
if( $ts1  $ts2 ):
 echo "Date 1 is greater than date2";
elseif($ts1 == $ts2):
 echo "date 1 is equal to date 2" ;
else:
 echo " date 2 is greater than date 1";
endif;

should work :)
Tom
At 09:50 AM 28/03/01 +, kaab kaoutar wrote:
Hi!

$date1="2001-1-7";$date2="2001-1-14";
if ($date1=$date2) echo "date1 is greater then date2";
else echo "date2 is greater then date1";
the result is the first :(
but it works for other dates!

Thanks

_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] comparing dates works sometimes and fails another time!

2001-03-28 Thread kaab kaoutar

Hi!

$date1="2001-1-7";$date2="2001-1-14";
if ($date1=$date2) echo "date1 is greater then date2";
else echo "date2 is greater then date1";
the result is the first :(
but it works for other dates!

Thanks

_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] comparing dates works sometimes and fails another time!

2001-03-28 Thread Renze Munnik

If you _do_ want to use this method for comparing dates (which isn't
realy a usual way of doing it... there date-functions) you should
fill up with leading 0's, like:

$date1="2001-01-07"; $date2="2001-01-14";

The reason is _very_ simple... You performing a text-compare here.
And let's face it... the characters "-1" (day of date2) are
"smaller" than "-7" (day in date1).

So...

RenzE


kaab kaoutar wrote:
 
 Hi!
 
 $date1="2001-1-7";$date2="2001-1-14";
 if ($date1=$date2) echo "date1 is greater then date2";
 else echo "date2 is greater then date1";
 the result is the first :(
 but it works for other dates!
 
 Thanks
 
 _
 Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] comparing dates works sometimes and fails another time!

2001-03-28 Thread elias

What are appropriate functions to do Date and Time comparison?
like:
  Date difference
  Date Comparison?
  Adding 'n' days to current date string value, Removing 'n' month, etc.
 Where can i find the date integer enconding used in PHP?
 Like i know how it's done in Delphi (as stored as a Double value)
 but in PHP, the date integer how is it encoded?

thanks.

"Renze Munnik" [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 If you _do_ want to use this method for comparing dates (which isn't
 realy a usual way of doing it... there date-functions) you should
 fill up with leading 0's, like:

 $date1="2001-01-07"; $date2="2001-01-14";

 The reason is _very_ simple... You performing a text-compare here.
 And let's face it... the characters "-1" (day of date2) are
 "smaller" than "-7" (day in date1).

 So...

 RenzE


 kaab kaoutar wrote:
 
  Hi!
 
  $date1="2001-1-7";$date2="2001-1-14";
  if ($date1=$date2) echo "date1 is greater then date2";
  else echo "date2 is greater then date1";
  the result is the first :(
  but it works for other dates!
 
  Thanks
 
 
_
  Get Your Private, Free E-mail from MSN Hotmail at
http://www.hotmail.com.
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]