datetime compare question

datetime compare question

am 28.10.2005 16:04:59 von Alan Robertson

Apologies for asking such a stupid question, but I've just spent the last
four hours trying to solve it myself and failed!
I'm a complert enovice at this php/mysql thing so I'll just get straight
into it.

I have create mysql db that has a field 'start_date' in the datetime format.
I also have a string in PHP formated as $expiry = date("Y-m-d H:i:s").

All I want is a select query that will return the rows of data where the
'start_date' field is less than the $expiry variable.
But I am having no luck what so ever.

$query = "SELECT * FROM `tbl_markets` WHERE 'start_date' < '$expiry'";

Not exactly rocket science - but I'm pulling my hair out here.

can anyone think what i need to do. I've tried using DateFormat on the
'start_date' incase it gets converted into a string from mysql, but that
didn't make any difference either.


Regards
Alan

Re: datetime compare question

am 28.10.2005 17:51:25 von zeldorblat

How about this:

$expiry = strtotime('2005-02-20 16:20:00'); //$expiry is a timestamp
$query = "SELECT * FROM tbl_market WHERE UNIX_TIMESTAMP(start_date) <
$expiry";

Re: datetime compare question

am 28.10.2005 19:41:59 von Alan Robertson

"ZeldorBlat" wrote in message
news:1130514685.898200.317640@f14g2000cwb.googlegroups.com.. .
> How about this:
>
> $expiry = strtotime('2005-02-20 16:20:00'); //$expiry is a timestamp
> $query = "SELECT * FROM tbl_market WHERE UNIX_TIMESTAMP(start_date) <
> $expiry";
>

Blooming 'ell.
That worked.
You've saved me a lifetime of scratching my head.

I still don't understand why my way didn't work, but now that it works I
aint touchning it.

Thanks a mill.

Regards
Alan