Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting date string to date

Tags:

string

date

php

I'm trying to use strtotime to convert date strings in the format Jan 14th 2011 to the format 2011-01-14 but it's not working.

Is this format not suitable for strtotime and if so, how can I convert it. The month is always in 3-letter format, like Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec

like image 502
sameold Avatar asked Sep 19 '26 05:09

sameold


1 Answers

$date_str = "Jan 14th 2011";
$date = date_parse_from_format('M jS Y', $date_str);

echo $date->format('Y-m-d');
like image 159
Cliff Avatar answered Sep 21 '26 18:09

Cliff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!