Extract Month & Date From ACF Date & Time

Quick Summary
- Pass the ACF Date Time Picker value from get_field() to strtotime(), then date() with M prints the short month and d the two-digit day.
- Use a Return Format like Y-m-d H:i:s, because strtotime() reads slashed dates as month/day and misreads formats such as d/m/Y.
- Use the code inside the loop, remove the //MONTH and //DATE labels that print on the page, and switch to date_i18n() for translated months.
Event listings often show the date as a small calendar badge, with the month abbreviation above the day number. If you store the event start in an Advanced Custom Fields (ACF) Date Time Picker field, this snippet pulls the month and the day out of it so you can style them separately.
Use it in a theme template inside the loop, because get_field() reads the field from the current post.
<?php
$ev_date_time = get_field('start_ev_date_time');
$eventDate = strtotime(get_field('start_ev_date_time'));
?>
//MONTH
<?php echo date('M', $eventDate); ?>
//DATE
<?php echo date('d', $eventDate); ?>How it works
get_field('start_ev_date_time')returns the field value as a string in the field’s Return Format, which you choose in the field settings (see ACF’s Date Time Picker documentation). Replacestart_ev_date_timewith your own field name.strtotime()turns that string into a Unix timestamp.date('M', $eventDate)prints the three-letter month, such as Apr, anddate('d', $eventDate)prints the day with a leading zero, such as 05.- Other PHP date characters work the same way, for example
Ffor the full month name orjfor the day without a leading zero.
Gotchas
strtotime()can misread some formats. With slashes it assumes the American month/day order, so a Return Format liked/m/Y g:i agives wrong dates or none at all. A format such asY-m-d H:i:sis safe.- The
//MONTHand//DATElabels sit outside the PHP tags, so they will be printed on the page. Remove them when you copy the code. $ev_date_timeisn’t used afterwards, so you can drop that line.date()always prints English month names. On a site in another language, usedate_i18n()with the same arguments.
If your theme shows events or dates from ACF fields, see my custom WordPress development services.
Related articles
- sorting a custom post type query by an ACF date field: order the event list before formatting each badge
- pre-filling an ACF date field with acf/load_field: give new events a default date
