PHPWeb Development

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

Recommended Tutorials for you


Tags

Anuj kumar

This is Anuj Kumar. I’m a professional web developer with 5+ years of 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. .

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Check Also
Close
Back to top button
Close
Close