Support

Account

Home Forums General Issues Format date/time

Solving

Format date/time

  • I’m using Advanced Custom Fields and I have installed the date/time plugin. I can successfully pullout the results of this field via:

    <?php the_field( "gig_datetime" ); ?>

    which results in something such as:

    Sunday 27 April 2014 12:19 am

    But I’m trying to format it to a format like:

    2004-02-12T15:19:21+00:00

    So far I’m trying:

    $format = "c";
    $timestamp” = get_field("gig_datetime");

    Then pulling out the time like:

    <?php echo date_i18n( $format, $timestamp” ); ?>

    However this is no longer using the value from the ACF and instead I think is using an American time value of todays date. I understand date_i18n uses localization which is obviously not what I want, however I’m not sure how to format the ACF data in the way I need. Help would be appreciated.

  • Hi,

    This is how you should use date_i18n with ACF:

    $dateformatstring = "l d F, Y";
    $unixtimestamp = strtotime(get_field('date_picker'));
    echo date_i18n($dateformatstring, $unixtimestamp);

    This depends on your blogs language setting. If you want to manually specify the locale in PHP, ignoring WordPress, you can do it like this:

    setlocale(LC_ALL, 'fr_FR');
    echo strftime("%A le %d %B, %Y");
    //with day of the week = mercredi le 18 septembre, 2013
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Format date/time’ is closed to new replies.