This question has already been answered:
The date comes in the format 01/05/2016. How to convert it to a type format 2016-01-05 using PHP
This question has already been answered:
The date comes in the format 01/05/2016. How to convert it to a type format 2016-01-05 using PHP
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
If you are sure that the input date is correct and its control is not needed, then:
$date="05.01.2016"; $my_date=preg_replace("/(\d\d)\\.(\d\d)\\.(\d{4})/","$3-$2-$1",$date); echo $my_date; Or
$date="05.01.2016"; $arr=explode(".",$date); $my_date=strftime("%F",mktime(0,0,0,$arr[1],$arr[0],$arr[2])); echo $my_date; If the question is only in the date conversion, and not how to store it in MySQL, then the shortest option:
date ('Ym-d', strtotime ('05 .01.2015 '));
Замечание: Даты в формате m/d/y или dmy разрешают неоднозначность с помощью анализа разделителей их элементов: если разделителем является слеш (/), то дата интерпретируется в американском формате m/d/y, если же разделителем является дефис (-) или точка (.), то подразумевается использование европейского форматаd-my. - Maxim TronenkoSource: https://ru.stackoverflow.com/questions/486501/
All Articles