johnnys2 Posted July 30, 2013 Share Posted July 30, 2013 Hi Guys, Just looking for some quick advice on code - newbie here My code is as follows <td>{$result['cdate']}</td> <td>{$result['mdate']}</td> This successfully outputs my date in the format 2013-05-08 12:24:04 - however I would like it as 08 July 2013 12:24:04 The cdate is a datetime and mdate is a timestamp in mysql database. I have been reading about srttotime and can't get my head around it, any help is appreciated. Thanks in advance, J Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted July 30, 2013 Share Posted July 30, 2013 I would suggest changing your query to SELECT ...,DATE_FORMAT(CONCAT(cdate, ' ', mdate), '%d %M %Y %H:%i:%s') AS mdate,... Quote Link to comment Share on other sites More sharing options...
johnnys2 Posted July 30, 2013 Author Share Posted July 30, 2013 thanks for the help is there no way of adding something like 'd-m-y' amongst the <td>{$result['mdate']}</td> - excuse my ignorance! Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted July 30, 2013 Share Posted July 30, 2013 I don't understand your question, sorry. Quote Link to comment Share on other sites More sharing options...
johnnys2 Posted July 30, 2013 Author Share Posted July 30, 2013 apologies, I will try to clarify In one of my other php pages I have the code below <td> '.date("d-M-Y H:i:s", strtotime($result['cdate'])).' </td> This successfully outputs this text 30-Jul-2013 11:55:00 Is it possible to implement such code into the code below (without having to change querys etc) <td>{$result['cdate']}</td> <td>{$result['mdate']}</td> This is a project I am taking over from another person, and just needs fine tuned to be completed. Thanks again for the help. If I'm making no sense let me know! J Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 30, 2013 Share Posted July 30, 2013 You have two options. You can either have the date formatted within your query - so you don't have to do anything with the value once returned. Or, you can format it within PHP. There are benefits and drawbacks to both and the determination would be based on many factors (e.g. do the date/times need to be timezone aware for the user). But, in either case, you can format the date in any manner you wish. strtotime() is only needed to convert the date string to a timestamp - it is the date() function that determines what the format it: http://php.net/manual/en/function.date.php For the format "08 July 2013 12:24:04", you would use "d F Y H:i:s" - this assumes you want the hour n 24 hour format. date("d F Y H:i:s", strtotime($result['cdate'])) Quote Link to comment Share on other sites More sharing options...
Solution Muddy_Funster Posted July 30, 2013 Solution Share Posted July 30, 2013 just apply the same successfull line of code to the other $result[] outputs to the rest of the outputs that you want to match that format. Sorry, I missread the first post and thought that you had the date in one column and the time in another. Quote Link to comment Share on other sites More sharing options...
johnnys2 Posted July 30, 2013 Author Share Posted July 30, 2013 (edited) thanks for the tips guys! OK now I have the code below; <td>Date of Request</td> <td>{$result[date("d-F-Y H:i:s", strtotime($result['cdate']))]}</td> <td>Date Last Modified</td> <td>{$result['mdate']}</td> The first row cdate (date of request) doesn't output any date at all now The second row mdate (date last modified) outputs 2013-07-30 11:55:00 Maybe I need to go away and start at the beginning with PHP! Edited July 30, 2013 by johnnys2 Quote Link to comment Share on other sites More sharing options...
johnnys2 Posted July 30, 2013 Author Share Posted July 30, 2013 sorted thanks guys 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.