Is this a complete wrong way to compare two dates?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Is this a complete wrong way to compare two dates?

Post by crazytopu »

Code: Select all

 SELECT * FROM `request` WHERE  required_by_date < 2007-03-25  
It gives inconsistent result, for example there is a required_by_date which is 2007-28-02 but it doesn't return the row.

Is this a complete wrong way to compare two dates?

P.S: requierd_by_date is a date field in the database.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Put the date in the sql in quotes. EG

Code: Select all

SELECT * FROM `request` WHERE  required_by_date < '2007-03-25'
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Hm, interesting :?

Didn't realise you need a quote. Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you don't quote it, it is understood to be a math expression to the database.
Post Reply