Q:

How to Convert a Date from yyyy-mm-dd to dd-mm-yyyy Format in PHP

0

How to Convert a Date from yyyy-mm-dd to dd-mm-yyyy Format in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the strtotime() Function

You can first use the PHP strtotime() function to convert any textual datetime into Unix timestamp, then simply use the PHP date() function to convert this timestamp into desired date format.

The following example will convert a date from yyyy-mm-dd format to dd-mm-yyyy.

<?php
$original_date = "2019-03-31";
 
// Creating timestamp from given date
$timestamp = strtotime($original_date);
 
// Creating new date format from that timestamp
$new_date = date("d-m-Y", $timestamp);
echo $new_date; // Outputs: 31-03-2019
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Convert a String to a Number in PHP... >>
<< How to Get the Current Year using PHP...