Reputation: 20926
This is my date format:
d.m.y
but I need it like dd.mm.yy
How can with php check format and if is d.m.y
then convert it to dd.mm.yy
and if is already dd.mm.yy
leave it.
If is y-m-d
conver it to yy-mm-dd
How can i do with regex?
Why regex. Because my datum is CONSTANT. And for each installation is different. But for some cases must be not d.m.y but dd.mm.yy for example.
but can be some other format also.
Upvotes: 0
Views: 92
Reputation: 6114
$show_date = DateTime::createFromFormat('d.m.Y', $dateInput)->format('Y-m-d');
Upvotes: 2
Reputation: 1420
You can use
$date = date('d.m.y', strtotime($your_date))
or
$date = new DateTime($your_date);
echo $date->format('d.m.y');
Upvotes: 1
Reputation: 32790
Try this :
$date = new DateTime('2000-01-01'); /// you need to convert you input date to this format
echo $date->format('d-m-y');
Upvotes: 1