How can I convert a date from a format like this 13/Février/2016
to 2016-02-13
(Y-m-d) ?
You will first need to transform the month to English or a numeric value.
then all of the above answers will work
$month_name=array("","Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août",
"Septembre","Octobre","Novembre","Décembre");
$dateinput = '13/'.array_search("Février",$month_name).'/2016';
$date = date("Y-m-d",strtotime(str_replace('/', '-', $dateinput)));
echo $date;
You need to reformat the datestring using the DateTime class, see below for the answer.
$myDateTime = DateTime::createFromFormat('DD/m/YY', $dateString);
$newDateString = $myDateTime->format('Y-m-d');
$myDateTime = DateTime::createFromFormat('DD/m/YY', $dateString);
$newDateString = $myDateTime->format('Y-m-d');
This may help you:)
<?php
$changedate = str_replace("/","-","13/February/2016");
echo date("Y-m-d",strtotime($changedate));
?>
You can use strftime()
and setlocale()
for other language.
$date = "13/Février/2016";
setlocale(LC_TIME, 'fr_FR');
echo strftime("%Y-%b-%d", strtotime($date));