How To Change Date Format In PHP?

PHP 8 , PHP

Nicesnippets

1034

03-06-2021


How To Change Date Format In PHP?

Hi guys,

Today i will explained to the How To Change Date Format In PHP. This example is so easy to use in php.Php convert date to provides strtotime() and date() function. We change the date format from one format to another.

Date conversion by using strtotime() and date() function. These are the built-in functions of PHP. strtotime() first converts the date into the seconds, and date() function is used to recreate the date in any format.

So let's start to the example and follow to the my all step.

Solution


date("d-m-Y", strtotime($orgDate));

Example :

This example to use (2021-06-03) date and create a (MM-DD-YYYY) format in php.

<?php

$date = "2021-06-03";

$newDate = date("d-m-Y", strtotime($date));

echo "New date format is: ".$newDate. " (MM-DD-YYYY)";

?>

Output :

New date format is: 03-06-2021 (MM-DD-YYYY)

So, finally we are done with our code we can get below output.


Recommended Posts