How to get a date in the format 5 - 7 Jan
if (get_field('event_from')) {
echo $datefrom->format('d.m.Y').' - ';
}
return 21.01.2020 - 22.01.2020
But I need a date in a different format for example 5 - 7 Jan
Please help.
How to get a date in the format 5 - 7 Jan
if (get_field('event_from')) {
echo $datefrom->format('d.m.Y').' - ';
}
return 21.01.2020 - 22.01.2020
But I need a date in a different format for example 5 - 7 Jan
Please help.
If the ACF-field is a datepicker, you could configure the return format in the field it self.
Setting it to j M
will give you the value "5 Jan"
'j' is numeric representation of day without a leading zero. 'M' is a short textual representation of a month, three letters.
Check the PHP-manual for more information: https://www.php.net/manual/en/function.date.php
Once the field is configured to return the date formated as above, you can just append the value to your string.
$date_string;
if (get_field('event_from')) {
$date_string = get_field('event_from') . ' - ';
}
if (get_field('event_to')) {
$date_string .= get_field('event_to');
}
echo $date_string;