Support

Account

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);