Search code examples
wordpressadvanced-custom-fields

ACF pro - return day with date picker


I use ACF pro for my wordpress. My datepicker field is a repeater field.

I need to return only the day.

my code :

<?php   
if( have_rows('dates') ):
while ( have_rows('dates') ) : the_row();
echo get_sub_field('date')."</br>";
endwhile;
else :
echo __( 'No dates available.','mywebsite' );
endif;
?>

Solution

  • You can set the return value of the date field.

    enter image description here

    EDIT

    Ok, so if you want to display two dates, one full and one is only day, you first need the return value to be the full date, for this example lets day it d/m/Y

    $full_date = get_sub_field('date'); // the full date (format d/m/Y);
    $day_from_date = DateTime::createFromFormat('d/m/Y', $full_date)->format('d'); // will get the day from the $full_date
    

    This will get you the result you need.

    See DateTime::createFromFormat for more information about the method