Support

Account

Home Forums General Issues Extract year and Month from date picker custom field Reply To: Extract year and Month from date picker custom field

  • In addition to Elliot’s suggested method, if you didn’t want to change the value saved to the database, you could use the DateTime ‘format’ method:

    
    $date = get_field("my_date_field");
    
    // assuming your return format is "Ymd"
    $dateTime = DateTime::createFromFormat("Ymd", $date);
    
    if ( is_object($dateTime) ) {
      $month = $dateTime->format('F');
      $year = $dateTime->format('Y');
      //...
    }