Cep Posted January 21, 2007 Share Posted January 21, 2007 Hello,I have a simple table with a date field, which has 4 records, 2 of which contain the date 2007-01-07In my sql I have stated,[code=php:0]$gsql = "SELECT * FROM cw_games WHERE gamedate = '2007-01-07'";[/code]The error I receive is,Function: get_lastgamesSELECT gsql:SELECT * FROM cw_games WHERE gamedate = '2007-01-07'SQL ERROR: Query was emptyThis makes no sense to me at all, even the date field type on MySQL's website suggests that the format is always input and output as YYYY-MM-DD so why is my query not picking up the fact that there are two records within the 4 that have the date 2007-01-07 ? Link to comment https://forums.phpfreaks.com/topic/35090-date-field-mysql-is-driving-me-up-the-wall/ Share on other sites More sharing options...
paul2463 Posted January 21, 2007 Share Posted January 21, 2007 silly question but worthy of an askthe column in your database is it type 'date' or type 'datetime'? Link to comment https://forums.phpfreaks.com/topic/35090-date-field-mysql-is-driving-me-up-the-wall/#findComment-165611 Share on other sites More sharing options...
paul2463 Posted January 21, 2007 Share Posted January 21, 2007 you could always tru the following anyway[code]$gsql = "SELECT * FROM cw_games WHERE DATE_FORMAT("%Y-%m-%d",gamedate) = '2007-01-07'";[/code]which will format what date you have in there to the way you are checking for it Link to comment https://forums.phpfreaks.com/topic/35090-date-field-mysql-is-driving-me-up-the-wall/#findComment-165612 Share on other sites More sharing options...
Cep Posted January 21, 2007 Author Share Posted January 21, 2007 its set to date, I can clearly see the date when I browse the table in phpmyadmin and there are two rows with the date 2007-01-07.I am literally reading in a string,$date = "2007-01-07";$gsql = "SELECT * FROM cw_games WHERE gamedate = '{$date}'"; Link to comment https://forums.phpfreaks.com/topic/35090-date-field-mysql-is-driving-me-up-the-wall/#findComment-165613 Share on other sites More sharing options...
paul2463 Posted January 21, 2007 Share Posted January 21, 2007 $gsql = "SELECT * FROM cw_games WHERE gamedate = '$date'";remove the curly braces they are not needed any more Link to comment https://forums.phpfreaks.com/topic/35090-date-field-mysql-is-driving-me-up-the-wall/#findComment-165625 Share on other sites More sharing options...
Cep Posted January 21, 2007 Author Share Posted January 21, 2007 Ah ok cheers! Link to comment https://forums.phpfreaks.com/topic/35090-date-field-mysql-is-driving-me-up-the-wall/#findComment-165627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.