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 Quote Link to comment 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. Quote Link to comment 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' Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 11, 2012 Share Posted September 11, 2012 What happened when you tried it? Quote Link to comment Share on other sites More sharing options...
Barand Posted September 11, 2012 Share Posted September 11, 2012 MySQL DATE function Quote Link to comment 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. 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.