0

i am using ACF to display an internationalized date with this code :

<?php
    $dateformatstring = "l j F Y";
    $unixtimestamp = strtotime(get_field('date'));
?>

<?php echo date_i18n($dateformatstring, $unixtimestamp); ?>

but i wish i could separate each part into span for example to obtain a result like this :

<span>*day number*</span><span>*week day*</span><span>*month*</span><span>*year*</span>

but despite many attemps, i couldn't make it -_- Thanks for your help ;-)

  • Why not just echo '<span>'.date_i18n('..', $timestamp).'</span><span>'.date_i18n(... (you get the idea) ? – kero Nov 14 '18 at 19:36
  • yes i get it ! :-) – studiok7 Nov 14 '18 at 19:44
2

thanks to @kero, i managed to do something like this :

<?php
    $dayNumber = "l";
    $weekDay = "j";
    $month = "F";
    $year = "Y";
    $unixtimestamp = strtotime(get_field('date'));
?>

<?php echo '<span>' . date_i18n($dayNumber, $unixtimestamp) . '</span>'; ?>
<?php echo '<span>' . date_i18n($weekDay, $unixtimestamp) . '</span>'; ?>
<?php echo '<span>' . date_i18n($month, $unixtimestamp) . '</span>'; ?>
<?php echo '<span>' . date_i18n($year, $unixtimestamp) . '</span>'; ?>

Not sure it is the best way to do it but it works. Thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.