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.
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))
- How to validate if input date (end date) in input field must be after a given date (start date) using express-validator ?
- How to validate if input date (start date) in input field must be before a given date (end date) using express-validator ?
- How to change the date format using AngularJS ?
- PHP date() format when inserting into datetime in MySQL
- How to set input type date in dd-mm-yyyy format using HTML ?
- Format a Date using ng-model in AngularJS
- PHP | Format Specifiers
- Format a number with leading zeros in PHP
- PHP | DateTime format() Function
- PHP | IntlDateFormatter format() Function
- PHP | Date and Time
- PHP | Converting string to Date and DateTime
- Convert timestamp to readable date/time in PHP
- PHP | Spreadsheet | Setting a date and/or time value in a cell
- Sort a multidimensional array by date element in PHP
- How to add days to $Date in PHP?
- How to get last day of a month from date in PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.