johnnyk Posted July 20, 2006 Share Posted July 20, 2006 I can never seem to get the date function to work:SELECT *, DATE_FORMAT(`datetime`, '%W, %M %D') AS `date`, DATE_FORMAT(`datetime`, '%l:%i %p') AS `time` FROM `table` WHERE `a` IS NULL AND DATE_FORMAT(`datetime`, '%Y') = '$year' AND DATE(`datetime`) >= '2006-07-20' ORDER BY `datetime` ASCHere's the mysql_error():You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(`datetime`) >= '2006-07-20' ORDER BY `datetime` ASC' at line 1I don't see a problem.I'm using MySQL 5.0.21 Quote Link to comment Share on other sites More sharing options...
fenway Posted July 20, 2006 Share Posted July 20, 2006 Well, there's nothing wrong with that syntax at all... I assume that your substitution for $year is correct? Post the query after the interpolation step. BTW, you really shouldn't name your column "datetime". Quote Link to comment Share on other sites More sharing options...
johnnyk Posted July 24, 2006 Author Share Posted July 24, 2006 This isn't the first time I've gotten "SQL error" things when the SQL was fine. It happened before and I don't know why. Interpolation? I am confused what you mean.And what's wrong with naming it datetime? I never name my columns according to their type, except for datetime. The php never uses $row['datetime']. I just split the datetime up to date and time using SQL. What else would I name it, and why would it matter? Quote Link to comment Share on other sites More sharing options...
shoz Posted July 25, 2006 Share Posted July 25, 2006 [quote author=johnnyk link=topic=101248.msg400446#msg400446 date=1153405332]I can never seem to get the date function to work:SELECT *, DATE_FORMAT(`datetime`, '%W, %M %D') AS `date`, DATE_FORMAT(`datetime`, '%l:%i %p') AS `time` FROM `table` WHERE `a` IS NULL AND DATE_FORMAT(`datetime`, '%Y') = '$year' AND DATE(`datetime`) >= '2006-07-20' ORDER BY `datetime` ASCHere's the mysql_error():You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(`datetime`) >= '2006-07-20' ORDER BY `datetime` ASC' at line 1I don't see a problem.I'm using MySQL 5.0.21[/quote]If that's the exact query you ran then I can only assume that your version of MYSQL is actually lower than 4.1. The syntax error you posted would be caused by the fact that the DATE function only became available in version 4.1.1 if that is the case.Run the query below using the same script to verify the version.[code]SELECT VERSION();[/code] Quote Link to comment Share on other sites More sharing options...
johnnyk Posted July 25, 2006 Author Share Posted July 25, 2006 5.0.21I had this problem before. It kept telling me there was an error in SQL syntax when there wasn't. Quote Link to comment Share on other sites More sharing options...
shoz Posted July 25, 2006 Share Posted July 25, 2006 Change the query to the following and post any errors. Remember to use the same script.[code]SELECT DAY('2006-01-02');[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.