MySQL problem with a Date field

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
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

MySQL problem with a Date field

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you looked at the CURRENT_DATE() function?
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

Yeah, I have just tried that, the same thing happens.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post 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.
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

Server restarted, problem has gone. Thanks for the help though feyd :D
Post Reply