wright67uk Posted January 6, 2013 Share Posted January 6, 2013 How can I change a date from YYYY-MM-DD to DD/MM/YYYY ? I have a date picker in a form which always posts in this format: 2013-01-30 When I process the form I would like to store this date into a variable but in this format 30/01/2013. So I need to replace dashes for slashes, and reverse the order of year, month, and date. Quote Link to comment https://forums.phpfreaks.com/topic/272764-changing-the-format-of-a-date/ Share on other sites More sharing options...
Jessica Posted January 6, 2013 Share Posted January 6, 2013 No, you want to store the date the way it is. That's the proper format to store a date. You can reformat it using date() when you want to display it, but store it in the ISO format. Quote Link to comment https://forums.phpfreaks.com/topic/272764-changing-the-format-of-a-date/#findComment-1403650 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2013 Share Posted January 6, 2013 (edited) You need to store the date in a DATE data type with the YYYY-MM-DD format. The only time you should format as DD/MM/YYYY is when you want to display it. edit: damn, the forum's post notification (or lack of) gets a -20 likes. Edited January 6, 2013 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/272764-changing-the-format-of-a-date/#findComment-1403653 Share on other sites More sharing options...
Barand Posted January 6, 2013 Share Posted January 6, 2013 edit: damn, the forum's post notification (or lack of) gets a -20 likes. Only -20. How generous! Along with the "What You See Is Nothing Like What You Get" editor! Quote Link to comment https://forums.phpfreaks.com/topic/272764-changing-the-format-of-a-date/#findComment-1403740 Share on other sites More sharing options...
PFMaBiSmAd Posted January 7, 2013 Share Posted January 7, 2013 Actually, the editor is a What You Shouldn't see Is What You Get. Quote Link to comment https://forums.phpfreaks.com/topic/272764-changing-the-format-of-a-date/#findComment-1403805 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.