How to change date format in PHP?

How to change date format in PHP?

In this post we will give you information about How to change date format in PHP?. Hear we will give you detail about How to change date format in PHP?And how to use it also give you demo for it if it is necessary.

In this post, i would like to share with you how do i change 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. we will convert date format using date() and strtotime() of php.

I will give you very simple example that helps you to simply change date formate in php. we most of need to change date format when you store date into database and when you display on list page. so i will give you bellow three example that will help you to easily convert date format in php.

So, let’s see three example, so you can use in your core php application.

Convert yyyy-mm-dd to mm/dd/yyyy in PHP

In this example we will add “2019-08-15” with (YYYY-MM-DD) format and we will change into MM/DD/YYYY format in php.

$myOriginalDate = "2019-08-15";

$myNewDate = date("m/d/Y", strtotime($myOriginalDate));

print_r($myNewDate);

Output:

08/15/2019

Convert yyyy-mm-dd to dd-mm-yyyy in PHP

In this example we will add “2019-08-15” with (YYYY-MM-DD) format and we will change into DD-MM-YYYY format in php.

$myOriginalDate = "2019-08-15";

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

print_r($myNewDate);

Output:

15-08-2019

Convert dd/mm/yyyy to yyyy-mm-dd in PHP

In this example we will add “15/08/2019” with (DD/MM/YYYY) format and we will change into YYYY-MM-DD format in php.

$myOriginalDate = "15/08/2019";

$myOriginalDate = str_replace('/', '-', $myOriginalDate );

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

print_r($myNewDate);

Output:

Also see:How to Convert String Date to Date Format in PHP?

2019-08-15

Now you can check anyone, it will help you.

I hope it can help you…

Hope this code and post will helped you for implement How to change date format in PHP?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

  +  28  =  33

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US