Page 1 of 1

MySQL problem with a Date field

Posted: Fri Apr 13, 2007 7:16 am
by SteveMellor
I hope this is the right place for this. Sorry if it isn't.

I've quite desperate now to get this problem sorted out.

I am trying to write an SQL statement that will pull out all records in a database where the date is higher than or equil to the current date. I have this:

"SELECT * FROM `events` WHERE `from` >= NOW() ORDER BY `from` ASC LIMIT 1"

'from' is a date field (not datetime).

Which seamed to work until Tuesday. The script was meant to drop the current event and replace it with the next in line. Well, it did it on Monday instead. Does anyone have any ideas on how I can get this to work properly?

Posted: Fri Apr 13, 2007 8:23 am
by feyd
Have you looked at the CURRENT_DATE() function?

Posted: Fri Apr 13, 2007 8:44 am
by SteveMellor
Yeah, I have just tried that, the same thing happens.

Posted: Fri Apr 13, 2007 8:47 am
by feyd
I can't reproduce your problem:

Code: Select all

mysql> SELECT '2007-04-13' >= '2007-04-13';
+------------------------------+
| '2007-04-13' >= '2007-04-13' |
+------------------------------+
|                            1 |
+------------------------------+
1 row in set (0.00 sec)

mysql> SELECT '2007-04-12' >= '2007-04-13';
+------------------------------+
| '2007-04-12' >= '2007-04-13' |
+------------------------------+
|                            0 |
+------------------------------+
1 row in set (0.00 sec)

mysql> SELECT '2007-04-14' >= '2007-04-13';
+------------------------------+
| '2007-04-14' >= '2007-04-13' |
+------------------------------+
|                            1 |
+------------------------------+
1 row in set (0.00 sec)

Posted: Fri Apr 13, 2007 8:56 am
by SteveMellor
No, I can't seam to reproduce it locally now :? but it's still like it online. I think this might be a glitch on the server. Will restart it and see if that helps.

Posted: Fri Apr 13, 2007 10:01 am
by SteveMellor
Server restarted, problem has gone. Thanks for the help though feyd :D