simonjk Posted September 10, 2012 Share Posted September 10, 2012 Hi, I have a column in my mysql database which is a TIMESTAMP. This automatically updates each time an entry is made. The TIMESTAMP update is in the format YYYY-MM-DD HH:MM;SS. I am trying to run the query below which retrieves data entered on a specific date from the table. However, it seems that the query reads the first date that is similar and that is output (i.e. 2012-09-07, rather than look for the date that has been requests (say, 2012-09-09). $daysresult = mysql_query("SELECT * FROM `hsgasjobsarchive` WHERE `Region`='Region' AND `Date` LIKE '$year-$month-$day_%'"); Am I doing something wrong in the like statement? I'd like the statement to ignore everything after $day. Thanks in advance, Simon Link to comment https://forums.phpfreaks.com/topic/268237-like-help-with-query-please/ Share on other sites More sharing options...
Pikachu2000 Posted September 10, 2012 Share Posted September 10, 2012 If you want specific data, use an equality comparison, not a LIKE comparison. Link to comment https://forums.phpfreaks.com/topic/268237-like-help-with-query-please/#findComment-1376848 Share on other sites More sharing options...
Barand Posted September 10, 2012 Share Posted September 10, 2012 DATE() function $date = '2012-09-09'; SELECT * FROM `hsgasjobsarchive` WHERE `Region`='Region' AND DATE(Date) = '$date' Link to comment https://forums.phpfreaks.com/topic/268237-like-help-with-query-please/#findComment-1376862 Share on other sites More sharing options...
simonjk Posted September 11, 2012 Author Share Posted September 11, 2012 Thanks for the replies, but I don't see how this will help as the format of the date in the Date column (from TIMESTAMP) is YYYY-MM-DD HH:MM:SS, e.g. 2012-09-08 10:20.22 ? Can the AND DATE(Date) = '$date' statement take a wildcard? As I could discard anything after $date? Thanks again, Simon Link to comment https://forums.phpfreaks.com/topic/268237-like-help-with-query-please/#findComment-1377024 Share on other sites More sharing options...
Pikachu2000 Posted September 11, 2012 Share Posted September 11, 2012 What happened when you tried it? Link to comment https://forums.phpfreaks.com/topic/268237-like-help-with-query-please/#findComment-1377031 Share on other sites More sharing options...
Barand Posted September 11, 2012 Share Posted September 11, 2012 MySQL DATE function Link to comment https://forums.phpfreaks.com/topic/268237-like-help-with-query-please/#findComment-1377032 Share on other sites More sharing options...
simonjk Posted September 11, 2012 Author Share Posted September 11, 2012 Sincere apologies guys, it does work...there was a code error further into the script. Thanks for your help, that's excellent. Link to comment https://forums.phpfreaks.com/topic/268237-like-help-with-query-please/#findComment-1377041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.