PHP program to change date format Last Updated : 11 May, 2018 Comments Improve Suggest changes 2 Likes Like Report You are given a string which contain date and time. Date in dd/mm/yyyy format and time in 12 hrs format.You have to convert date in yyyy/mm/dd format and time in 24 hrs format. Examples: Input : $date = "12/05/2018 10:12 AM" Output : 2018-05-12 10:12:00 Input : $date = "06/12/2014 04:13 PM" Output : 2014-12-06 16:13:00 First we will convert date to unix timestamp using strtotime() and then use date() to convert it to a specific format(The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT)) php <?php // function to convert string and print function convertString ($date) { // convert date and time to seconds $sec = strtotime($date); // convert seconds into a specific format $date = date("Y-m-d H:i", $sec); // append seconds to the date and time $date = $date . ":00"; // print final date and time echo $date; } // Driver code $date = "06/12/2014 04:13 PM"; convertString($date); ?> Output: 2014-06-12 16:13:00 Create Quiz Comment S Shivam.Pradhan Follow 2 Improve S Shivam.Pradhan Follow 2 Improve Article Tags : Misc Web Technologies PHP PHP-date-time Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like