Home Forums General Issues Problems with date (dd/mm) (mm/dd)


Problems with date (dd/mm) (mm/dd)

  • I use ACF and the Gravity Forms + Custom Post Types plugin so users can create a new event from a front-end Gravity form that becomes an unpublished CPT (Events) when submitted.

    I have ACF setting a start and end date for an event via a date picker.

    Save Format and Display Format are both set to dd/mm/yy (I can’t use the recommended yymmdd Save Format because this is the only format where the date will be populated from the frontend form).

    Every area I can think of is set to dd/mm/yy BUT…

    When I use this code to display the Start Date (it’s duplicated for End Date) it acts like the date has been parsed as MM/DD/YY:

    <?php $date = get_field(‘start_date’);
    $date2 = date(“j F Y”, strtotime($date)); ?>

    echo ‘<h3>Start date</h3>’ . $date2 . ‘


    The date picker of 04/03/16 when checked in ACF is selecting 4 March 2016 as expected, but output from the code above shows it as 3 April 2016.

    I’ve spend a long time trying to work out where I might be going wrong here but have not found it. If I set a date like 17/09/16 (September 17) the output is 01/01/1970 so the code is obviously seeing it as 9th of *17th month* and recognising it as a dud date.

    Any assistance would be gratefully received.

  • Hi @milkstudio

    The strtotime() function will assume that you use the American formatting when you use ‘/’ as the date separator. Kindly use or replace it to ‘-‘ instead to make it thinks that you use the European formatting. This page should give you more idea about it:

    Hope this helps.

  • Legend – thanks so much for that @James ! I never would have worked that out. Much appreciated 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.