PHPGurukul

How to change date format in PHP

In this tutorial we will learn how to chnage the date format in PHP.

In this tutorial we will use strtotime() and date() funtion.

The strtotime() funtion used to convert an English textual date-time description to a UNIX timestamp.We can return the English textual date-time in date format using the date() function.

Change dd/mm/yyyy to yyyy-mm-dd

<?php
$originale_date = "18/09/2019";
$date = str_replace('/', '-', $originale_date );
$new_Date = date("Y-m-d", strtotime($date));
echo $new_Date;
?>
Output

2019-09-18

Change yyyy-mm-dd to dd-mm-yyyy

<?php
$originale_date = "2019-09-18";
$new_Date = date("d-m-Y", strtotime($originale_date));
echo $new_Date;
?>
Output

18-09-2019

Change yyyy-mm-dd to mm-dd-yyyy

<?php
$originale_date = "2019-09-18";
$new_Date = date("m-d-Y", strtotime($originale_date));
echo $new_Date;
?>
Output

09-18-2019

Anuj Kumar

This is Anuj Kumar. I’m a professional web developer with 4+ year experience. I write blogs in my free time. I love to learn new technologies and share with others.
I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials.
.

Recommended Tutorials for you


1 comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Web Hosting with a FREE domain. On sale ₹99.00/mo

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.