Home › Forums › General Issues › Set month and year from a date field › Reply To: Set month and year from a date field
So ive managed to get it working using the following. Any suggestions?
function set_event_month($post_id, $post, $update) {
$event_date = get_field('event_date_start', $post_id, FALSE ,FALSE); // Event Start Date
$event_date = new DateTime($event_date);
$event_date = $event_date->format('F Y'); // Format date to month and year
update_field('event_month_year', $event_date); // Update field
}
add_action('save_post', 'set_event_month', 10, 3);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.