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.
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example