0
votes

I've got a new question for you, i'm trying to change the date format of the repeater field in a french one !

<?php $rows = get_field( 'evenement' ); ?>
<?php
$first_row_date = $rows[0]['date_debut_evenement'];
$last_row = end( $rows );
$last_row_date = $last_row['date_debut_evenement']; 
?>

<?php if( $last_row_date != $first_row_date ) : ?> 
<div class="bloc-date">
Du <?php echo $first_row_date; ?> au <?php echo $last_row_date; ?>
</div>
<?php else: ?>
<div class="bloc-date">
Le <?php echo $first_row_date; ?>
</div>
<?php endif; ?>

In an other page i've got this code working well, that show the french format date :

<?php 
    $dateformatstring = "D d M Y";
    $start_date = strtotime(get_sub_field('date_debut_evenement', false, false));
    $finish_date = strtotime(get_sub_field('date_fin_evenement', false, false));
    ?>      

    <div class="bloc-date" style="display:inline-block;">
    <?php if ($start_date == $finish_date) {
    echo date_i18n($dateformatstring, $start_date);
    } else {
    echo "Du "; echo date_i18n($dateformatstring, $start_date); echo " au ";
    echo date_i18n($dateformatstring, $finish_date);
    }?>     
    </div>

Thanks !

1
So... what's exactly the problem? If you got it working in one place just adapt the same solution. - Jordi Nebot
The problem is with the rows, i don't know which code to use to get the last_row of the sub field and to change the format of the date ! I don't know it it's very clear :) - Ben Belek

1 Answers

0
votes

You should try to retrieve your evenement field with the false 2nd parameter, like this:
$rows = get_field( 'evenement', false, false );
The 1st false represents the current post while the 2nd one tells ACF to get the raw data, whithout trying to convert it in another date format.

Then adjust your code from your working example by inserting a $dateformatstring = "D d M Y"; line and use date_i18n().