I have an ACF text field for a CPT that is holding a date in DD/MM/YYYY format (it's a text field and not a datepicker field as the data was imported from a CSV file).
My Wordpress loop then sorts by this field in DESC order but of course as it stands this means it displays the entries for the 31st of the month first as the day is the first part of the string. Is there any way to convert this field on-the-fly so it reads YYYY/MM/DD before being parsed by the loop?
I know how to output the date in the format I want in the front-end:
$date = the_field('date'); // eg. 15/05/2020
$orgD = substr($date, 0, 2);
$orgM = substr($date, 3, 2);
$orgY = substr($date, 6, 4);
$newFormat = $orgY . $orgM . $orgD;
$newDate = date("Y/m/d", strtotime($newFormat)); // eg. 2020/05/15
But I'm sure that doesn't help in any way for this purpose.
Is there a function I can add that will convert it or create a new custom field in the alternative format?