Forum Moderators: coopster

Message Too Old, No Replies

Compare two dates

very very simple question

         

Anyango

7:02 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey folks

comparing UNIX timestamps is no biggie but i have
to compare dates like this

$expiry_date="01/22/2007 05:42 PM";

to be compared with

$now= "01/22/2006 05:42 PM";

and just want a simple TRUE/FALSE return for the condition

"If expiry date has arrived? if its expiry date today or expiry date has passed?"

easy?

simon2263

7:12 pm on Jan 23, 2006 (gmt 0)

10+ Year Member



Try the PHP function strtotime() - this converts a date in string format into a unix timestamp, so may allow you to perform the comparison.

Simon

Anyango

7:41 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks a bunch Simon.

That Helps.

another question please. is there a way MYSQL can return unix timestamp of a date stored in one of its string fields as

date="01/22/2007 05:42 PM";

or in other words is there a MYSQL function which workss same as strotime()?

Moosetick

7:46 pm on Jan 23, 2006 (gmt 0)

10+ Year Member



How about something like...

<?php
$expiry_date="01/22/2007 05:42 PM";
$now= "01/22/2006 05:42 PM";

if ($expiry_date > $now) echo "still good";
else echo "your time has passed";

?>

Anyango

8:30 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Simon and Moosetick.

Got it ;)