moisesbr Posted July 27, 2013 Share Posted July 27, 2013 Hi, I have some doubts as date format is displayed is 2013-07-25 yy/mm/dd, as it is in database. 1-How/is it possible to format dd/mm/yy in database ? 2-How to format dd/mm/yy in HTML.3- Is it right to format it dd/mm/yy in database, or is it mandatory it to be yy/mm/dd and being formated at display moment ?Regards Moises Quote Link to comment https://forums.phpfreaks.com/topic/280566-date-format/ Share on other sites More sharing options...
Barand Posted July 27, 2013 Share Posted July 27, 2013 Continue to save dates in your database as yyyy-mm-dd as other formats are useless for date comparisons, sorting and use of mysql date functions. To output as dd/mm/yy you have 2 options 1. format in the query using DATE_FORMAT() function in mysql SELECT DATE_FORMAT(datefield, '%d/%m/%y') as date ... 2. use php date() function echo date('d/m/y', strtotime($dbdate)); Quote Link to comment https://forums.phpfreaks.com/topic/280566-date-format/#findComment-1442393 Share on other sites More sharing options...
moisesbr Posted July 27, 2013 Author Share Posted July 27, 2013 I used, echo date('d/m/y', strtotime($dbdate)); It worked but returns 2 digits year.I would like to set year to 4 digits. Quote Link to comment https://forums.phpfreaks.com/topic/280566-date-format/#findComment-1442397 Share on other sites More sharing options...
Barand Posted July 27, 2013 Share Posted July 27, 2013 use 'd/m/Y' then see date Quote Link to comment https://forums.phpfreaks.com/topic/280566-date-format/#findComment-1442399 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.