Page 1 of 1

Help with php/MySQL query [solved]

Posted: Tue Sep 18, 2007 9:32 am
by lkalisky
Hello,

I'm trying to pull records from a MySQL database using a sql query - to pull records where the "exp_date" field is greater than or equal to today. How do I do this?

Here is my query:

Code: Select all

$query = "SELECT v_title,link_id,v_descr,hw_added,hw_region_id,approved,user_approved,exp_date FROM ec3_ad WHERE hw_feat=1 AND approved=1 AND user_approved=1 AND hw_region_id=103 AND exp_date>=strftime('%d %b %Y %H:%M:%S') ORDER BY hw_added DESC LIMIT 20";
... but this is obviously not working because I don't know how to add today's date/time dynamically to the query.

Any help would be great!

[/quote]

Posted: Tue Sep 18, 2007 9:45 am
by CoderGoblin

Code: Select all

SELECT v_title,link_id,v_descr,hw_added,hw_region_id,approved,user_approved,exp_date FROM ec3_ad WHERE hw_feat=1 AND approved=1 AND user_approved=1 AND hw_region_id=103 AND exp_date>=NOW() ORDER BY hw_added DESC LIMIT 20
Would work in postgres. It uses the SQL "now()" to get the current information based on the current SQL server time. Not sure if it is the same in MySQL. If not I'm sure someone will let you know.

works!

Posted: Tue Sep 18, 2007 9:52 am
by lkalisky
Thanks for that... it does work in MySQL.