ianhaney Posted November 24, 2015 Share Posted November 24, 2015 Hi Sorry quick one, I am trying to make the date format into UK format and have entered the following into the SELECT query but is returning 0 results where as it should have two results I have the following SQL query $sql=$dbh->prepare("SELECT e.emp_id , t.task_id , t.customer_name , t.customer_phone , t.customer_address , DATE FORMAT(t.date_of_repair,'%d/%m/%Y') AS date_of_repair , t.description , t.status FROM employee e JOIN assignment a ON e.emp_id = a.emp_id JOIN task t ON a.task_id = t.task_id WHERE e.emp_id = ?"); $sql->execute(array($_SESSION['user'])); Quote Link to comment https://forums.phpfreaks.com/topic/299569-uk-date-format-in-select-query/ Share on other sites More sharing options...
ianhaney Posted November 24, 2015 Author Share Posted November 24, 2015 Sorry I did it another way by doing the following I added in this below date_default_timezone_set('Europe/London'); Then I did the following echo "<td>" . date('d/m/Y', strtotime($row->date_of_repair)) . "</td>"; Works perfect this way Quote Link to comment https://forums.phpfreaks.com/topic/299569-uk-date-format-in-select-query/#findComment-1527052 Share on other sites More sharing options...
Barand Posted November 24, 2015 Share Posted November 24, 2015 DATE FORMAT should not be two words, it's DATEunderscoreFORMAT eg SELECT DATE_FORMAT(t.date_of_repair, '%d/%m/%Y') Quote Link to comment https://forums.phpfreaks.com/topic/299569-uk-date-format-in-select-query/#findComment-1527055 Share on other sites More sharing options...
ianhaney Posted November 24, 2015 Author Share Posted November 24, 2015 Ahh ok what way is better or does it not matter as much if done the way I have done it or the DATE_FORMAT way? Quote Link to comment https://forums.phpfreaks.com/topic/299569-uk-date-format-in-select-query/#findComment-1527069 Share on other sites More sharing options...
Barand Posted November 24, 2015 Share Posted November 24, 2015 No hard and fast rule. If all you want to do with date is display it then it doesn't really matter, though it's easier to to do it in the query. If you need to do some further processing of the date in your PHP then select the raw date (yyyy-mm-dd) in the query, as d/m/y it useless for anything other than display. Quote Link to comment https://forums.phpfreaks.com/topic/299569-uk-date-format-in-select-query/#findComment-1527072 Share on other sites More sharing options...
ianhaney Posted November 24, 2015 Author Share Posted November 24, 2015 Ok Thank you for the advice and replies, appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/299569-uk-date-format-in-select-query/#findComment-1527074 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.