problem filtering dates

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
Beebosoft
Forum Newbie
Posts: 12
Joined: Mon Jun 25, 2007 9:18 am

problem filtering dates

Post by Beebosoft »

I have a table which includes details of events but I only want to show those that are not in the past.
I am getting todays date in the format in which it is stored in my table.

Code: Select all

$today = date("Y- m- d");
my sql statement is:

Code: Select all

$sql = "SELECT * FROM rsu WHERE scheme LIKE '$scheme' AND webdate >= '$today'  ORDER BY webdate ASC ";
The results display all the events in my table .

What have i got wrong with my syntax please or is there a better way to do this that a simple lass can understand

Any help appreciated
Nuts
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: problem filtering dates

Post by Zoxive »

Code: Select all

SELECT * FROM rsu WHERE scheme LIKE '$scheme' AND DATE_FORMAT(webdate,'%Y-%m-%d') >= '$today'  ORDER BY webdate ASC
Beebosoft
Forum Newbie
Posts: 12
Joined: Mon Jun 25, 2007 9:18 am

Post by Beebosoft »

Thanks, I tried that and it still seems to be ignoring the "DATE_FORMAT(webdate,'%Y-%m-%d') >= '$today' " part as all events are still being shown in the results
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Beebosoft wrote:Thanks, I tried that and it still seems to be ignoring the "DATE_FORMAT(webdate,'%Y-%m-%d') >= '$today' " part as all events are still being shown in the results
In your original post, you have spaces after the each "-"

Code: Select all

$today = date("Y-m-d"); // There were spaces after each -
When debugging try echoing out what php sees, so for your sql statement, echo it, and see if it sees what you want it to see.
Beebosoft
Forum Newbie
Posts: 12
Joined: Mon Jun 25, 2007 9:18 am

Post by Beebosoft »

Thanks Zoxive spaces are the bane of my life
Nuts
Post Reply