Click to See Complete Forum and Search --> : mySQL Date issues


cwilkey
10-24-2005, 01:30 PM
Hello. I need help with the following statment:

SELECT * FROM community WHERE date BETWEEN curdate() AND (curdate()=1)

It doesn't work. CURDATE() prints yyyy-mm-dd and CURDATE()+1 prints yyyymmdd.

Is there anyway to make the formatting match up?

NogDog
10-24-2005, 02:20 PM
I think this would do it:

SELECT * FROM `community` WHERE DATEDIFF(`date`, DATE_ADD(CURRDATE() INTERVAL 1 DAY)) <= 1

ava
10-25-2005, 01:49 AM
Well, I suppose you could user CURDATE()+0 to make it the same format but this works too:

SELECT
*
FROM
community
WHERE
'date' >= CURDATE()
and 'date' <= DATE_ADD(CURDATE(), INTERVAL 1 DAY)I'm not a big fan of the Between-statement as you can see.

NogDog's code if definitely not correct though. First, there's some syntax errors... it's CURDATE() with one R, and you need to add a comma after the CURDATE. Also, more importantly, there's no lower limit on the date. This will generate all dates before tomorrow, so also the ones before today.

cwilkey
10-26-2005, 09:08 AM
Thanks everyone!