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
function convertString ( $date )
{
$sec = strtotime ( $date );
$date = date ( "Y-m-d H:i" , $sec );
$date = $date . ":00" ;
echo $date ;
}
$date = "06/12/2014 04:13 PM" ;
convertString( $date );
?>
|
Output:
2014-06-12 16:13:00
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!