For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > October 2005 > datetime compare question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author datetime compare question
Alan Robertson

2005-10-28, 6:57 pm

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


ZeldorBlat

2005-10-28, 6:57 pm

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";

Alan Robertson

2005-10-28, 6:57 pm


"ZeldorBlat" <zeldorblat@gmail.com> 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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com