How to change date format in PHP?

How to change date format in PHP?

In this post, i would like to share with you how do i change date format in PHP

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:

2019-08-15

Now you can check anyone, it will help you.

I hope it can help you...

php web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...

PHP Website Development

Skenix Infotech is a leading PHP Web Development Company that helps companies get results with industry best practices. Get affordable PHP Development Services.

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

Hire PHP Developer

Looking to develop a PHP based website from scratch or revamp your existing website? **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")** has always been an industry leader for companies and business owners looking to hire...

Hire Web Developer

Looking for an attractive & user-friendly web developer? HourlyDeveloper.io, a leading web, and mobile app development company, offers web developers for hire through flexible engagement models. You can **[Hire Web...