Nodral Posted December 1, 2011 Share Posted December 1, 2011 Hi All Any ideas what is wrong with this query? SELECT count(*) as number WHERE ed = 429 AND YEAR(StartDate) = '2007' Data is as below ID ED CourseName StartDate 1405 429 In Search of Promoters 2011-02-01 10:00:00 1406 429 Managing the Customer Experience 2011-02-15 09:30:00 1407 635 Driver Awareness 2009-12-08 09:00:00 1408 635 Time Management 2007-03-23 10:00:00 1409 635 Fleet Administration 2005-04-13 10:00:00 1410 635 Coaching and Counselling Skills 2004-04-06 10:00:00 Error Code: 1064 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 'WHERE ed = 429 AND YEAR(StartDate) = '2007'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/252220-date-formatting-again/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 1, 2011 Share Posted December 1, 2011 Your query does not have a FROM table_name term in it. Quote Link to comment https://forums.phpfreaks.com/topic/252220-date-formatting-again/#findComment-1293076 Share on other sites More sharing options...
fenway Posted December 1, 2011 Share Posted December 1, 2011 Your query does not have a FROM table_name term in it. That's pure gold. Quote Link to comment https://forums.phpfreaks.com/topic/252220-date-formatting-again/#findComment-1293098 Share on other sites More sharing options...
Nodral Posted December 1, 2011 Author Share Posted December 1, 2011 Sorry guys, been a long day (and getting longer!!) Now, same table, why doesn't this work? SELECT coursename, DATE_FORMAT('startdate', %D, %M, %Y) as start FROM courses WHERE ed = 429 AND startdate > '2007-01-01' ORDER BY startdate Quote Link to comment https://forums.phpfreaks.com/topic/252220-date-formatting-again/#findComment-1293101 Share on other sites More sharing options...
Pikachu2000 Posted December 1, 2011 Share Posted December 1, 2011 In what way doesn't it work? Quote Link to comment https://forums.phpfreaks.com/topic/252220-date-formatting-again/#findComment-1293102 Share on other sites More sharing options...
mikosiko Posted December 1, 2011 Share Posted December 1, 2011 read DATE_FORMAT(date,format) Formats the date value according to the format string. http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format and look what you wrote Quote Link to comment https://forums.phpfreaks.com/topic/252220-date-formatting-again/#findComment-1293103 Share on other sites More sharing options...
ManiacDan Posted December 1, 2011 Share Posted December 1, 2011 To just get right to the point, you need to quote your strings. Both of these errors have been basic mysql syntax problems. Quote Link to comment https://forums.phpfreaks.com/topic/252220-date-formatting-again/#findComment-1293105 Share on other sites More sharing options...
ManiacDan Posted December 1, 2011 Share Posted December 1, 2011 Just re-visited this thread to realize: You need to quote your format string, NOT your column name. Three basic syntax errors. Quote Link to comment https://forums.phpfreaks.com/topic/252220-date-formatting-again/#findComment-1293226 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.