Reputation: 161
How to convert "Friday 20th of March 2015" into "2015-03-20" in Php ?
Options Tried (Failed):
$time = strtotime(stripslashes("Friday 20th of March 2015"));
echo date("Y-m-d",$time);
$time = strtotime("Friday 20th of March 2015");
echo date("Y-m-d",$time);
Option 2 (Failed):
$old_date = date('Friday 20th of March 2015');
$old_date_timestamp = strtotime($old_date);
$new_date = date('Y-m-d', $old_date_timestamp);
echo $new_date;
Option 3 (Failed):
$date = DateTime::createFromFormat('l d of F Y', 'Friday 20th of March 2015');
$new_date_format = $date->format('Y-m-d');
echo $new_date_format;
Duplicate Entries That Didn't Work Out: How to convert "Day, dd Month yyyy" to "yyyy-mm-dd" in php
Convert one date format into another in PHP
Upvotes: 1
Views: 400
Reputation: 161
This Code Works:
$date = DateTime::createFromFormat('l dS \o\f F Y', 'Friday 20th of March 2015');
$new_date_format = $date->format('Y-m-d');
echo $new_date_format;
Upvotes: 1