Changing The Format Of A Date In Php Using Datetime
Added on 25th January 2019 in Snippet
The following snippet of code allows you to convert a date from one format to another easily in PHP by using the built in DateTime class.
An Example of this would be to conver a standard UK date to a Database Friendly date such as 01/01/1988 to 1998-01-01
$date = DateTime::createFromFormat("d/m/Y","01/02/2017");
$formatted = $date->format("Y-m-d");
Hi there, I am christopher shaw, a software developer form South Yorkshire, England.
I love tinkering with all things tech, and opened this website as a web presence for myself and a place to keep my notes and snippets. Hopefully you will find something here to help