I am trying to achieve this:
getFormat("Jan 2020") // returns: M Y
getFormat("01 Feb 2020") // returns: d M Y
getFormat("01-January-2020") // returns: d-F-Y
Idea is to basically reverse engineer the php date
This is what I've tried so far:
public function getFormat($date){
$date = strtolower($date);
$formats = array(
"F" => array("january","february","march","april","may","june","july","august","september","october","november","december"),
"M" => array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"),
);
foreach($formats as $format=>$data) {
foreach($data as $d)
if (stripos($date,$d) !== false) $date = str_replace($d,$format,$date);
}
return $date;
}
This would work for months or days but I don't think this technique would ever work for numeric values.
12-12-12is not possible I hope?