Categories: PHP

How to change date format in PHP?

to convert the date-time layout Hypertext Preprocessor presents strtotime() and date() feature. We trade the date format from one layout to another. built-IN integrated – we’ve saved date integrated MM-DD-YYYY format integrated a variable, and we need to change it to DD-MM-YYYY format.
we will gabuiltintegrated this conversion built-in built-in the use of strtotime() and date() function. The strtotime() first converts the date integratedto the seconds, and then date() function is used to reconstruct the date integrated any layout. beneath a few examples are given to transform the date layout.
change YYYY-MM-DD to DD-MM-YYYY
integrated beneath built integrated, we’ve date 2019-09-15 built-in YYYY-MM-DD format, and we are able to convert this to 15-09-2019 integrated DD-MM-YYYY layout.

Output
New date layout is: 15-09-2019 (DD-MM-YYYY)
change YYYY-MM-DD to MM-DD-YYYY
built-in the under example, we’ve date 2019-02-26 built-in YYYY-MM-DD layout, and we are able to convert this to 02-26-2019 (MM-DD-YYYY) format.

Output
New date format is: 02-26-2019 (MM-DD-YYYY)
alternate DD-MM-YYYY to YYYY-MM-DD
built-inside the integrated below built-in, we’ve got date 17-07-2012 integrated DD-MM-YYYY layout, and we will convert this to 2012-07-17 (YYYY-MM-DD) format.

Output
New date format is: 2012-07-17 (YYYY-MM-DD)

convert date time into D-M-Y Format

$date=date_create($created_on );
$bdate=date_format($date,”dS M, Y”);

in above example $created_on store your date time value and covert them into D-M-Y format

Output

14th Dec, 2015

Basant

Recent Posts

How to make dependent dropdown of state and district using cakephp2 form?

Creating dependent dropdowns in CakePHP 2 involves using AJAX to dynamically load data into the…

18 hours ago

How to make id as auto increment in postgrey SQL?

just add below code in column properties id Default input Method: 1nextval('form_submissions_id_seq'::regclass) Method: 2 Via…

21 hours ago

How to Add Auto Increment to a Column in PostgreSQL ?

Learn how to efficiently set up auto-increment columns in PostgreSQL with this step-by-step guide. From…

1 month ago