You can assemble something simpler than suggested in the link. The first step is to define two arrays one for search and one for substitution (from Portuguese to English) because the names of the months or days of the week cannot be converted into a valid date if specified in Portuguese. Note that the first element of $en
is a glass that will be replaced by nothing.
After cleaning (replaced with str_ireplace()
) the string just call the method createFromFormat()
of DateTIme
defined the input format that in the case is the day (d
) following the month in full (F
) and last the four-digit year (Y
).
format()
sets the format you want Y-m-d
.
$pt = [',', 'janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'];
$en = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
$data = DateTime::createFromFormat('d F Y', str_ireplace($pt, $en,'22 maio, 2018'));
echo $data->format('Y-m-d');
Example - ideone
Need to adapt a little more in general lines is this => How to make a full date a common date?
– rray
Dude,
Outubro
is in Portuguese even?– Wallace Maxters
Yeah, bro. I tried those answers and none of them worked.
– wDrik
@wDrik doesn’t have that date the bank doesn’t? You really need to take the one that comes from WP? Or WP saves it so in the bank (if it is, it is WP’s mess)
– Wallace Maxters
So bro is how wordpress is returning. = / do a query for this I think will give more trampo! kkkkk
– wDrik
get_post_meta( $id_request, "Delivery Date", true ) is returning the date correctly?
– Everton Neri