php date time formatting

// THIS IS INVALID, WOULD IMPLY MONTH == 19
$external “19/10/2016 14:48:21”;

// HOWEVER WE CAN INJECT THE FORMATTING WHEN WE DECODE THE DATE
$format “d/m/Y H:i:s”;
$dateobj DateTime::createFromFormat($format$external);

 
echo $dateobj->format(‘Y-m-d H:i:s’);
 
 
Or
$date = new DateTime(‘2000-01-01’);
echo $date->format(‘Y-m-d H:i:s’);
 
to get current datetime simply:
$date = new DateTime();
Sources:
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s