Help with php/MySQL query [solved]

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lkalisky
Forum Newbie
Posts: 2
Joined: Tue Sep 18, 2007 9:28 am

Help with php/MySQL query [solved]

Post 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]
Last edited by lkalisky on Tue Sep 18, 2007 9:53 am, edited 1 time in total.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
lkalisky
Forum Newbie
Posts: 2
Joined: Tue Sep 18, 2007 9:28 am

works!

Post by lkalisky »

Thanks for that... it does work in MySQL.
Post Reply