angeo
answered May 1 '23 00:00
To convert one date format into another in PHP, you can use the date() and strtotime() functions. The date() function is used to format a date and time string, while the strtotime() function is used to convert a string to a Unix timestamp.
Here is an example of how to convert a date from one format to another:
$date_str = '2023-05-05 13:30:00'; // date string in the original format
$date = date('d/m/Y H:i:s', strtotime($date_str)); // convert to the new format
echo $date; // output the converted date
In this example, the date_str variable contains the date in the original format of Y-m-d H:i:s (year-month-day hour:minute:second). The strtotime() function converts this string to a Unix timestamp, which can be passed to the date() function as the second parameter to format the date in the desired format of d/m/Y H:i:s (day/month/year hour:minute:second). Finally, the converted date is output using the echo statement.