In this tutorial, We will learn how to change the date format DD/MM/YYYY to YYYY-MM-DD, MM-DD-YYYY to YYYY-MM-DD, d/m/Y to Y-m-d in PHP.



Change yyyy-mm-dd to mm/dd/yyyy  format in PHP

$myOriginalDate = "2021-02-15";
  
$myNewDate = date("m/d/Y", strtotime($myOriginalDate));
   
print_r($myNewDate);


Output:

02/15/2021


Change yyyy-mm-dd to dd-mm-yyyy format in PHP

<?php
$myOriginalDate = "2019-08-15";
$myNewDate = date("d-m-Y", strtotime($myOriginalDate));
print_r($myNewDate);


Output:

15-08-2019

Change dd/mm/yyyy to yyyy-mm-dd format in PHP

<?php
$myOriginalDate = "15/08/2019";
  
$myOriginalDate = str_replace('/', '-', $myOriginalDate );
$myNewDate = date("Y-m-d", strtotime($myOriginalDate));
   
print_r($myNewDate);


Output:

2019-08-15