Support

Account

Home Forums General Issues Date Picker – Output changes depending on editor timezone?

Helping

Date Picker – Output changes depending on editor timezone?

  • Hi, I’m new to using ACF and still learning PHP so please bear with me.

    I’m helping to maintain a website where one of the custom fields is a package start date. The field type is date picker and the save format is “@” (which I believe means unix time).

    The general wordpress settings are set to the timezone of most of the website editors (UTC+8) and when someone from this timezone enters a date of 25th for example, it appears correctly as 25th.

    However when an editor from a further ahead timezone of UTC+10 enters a date it appears as one day earlier on the website. (If she enters 25th, it appears incorrectly as 24th). The issue can be fixed if someone from the “normal” UTC+8 timezone re-saves the package.

    This is the code in the functions file to show the package time:

        $event_startdate_raw = intval(get_field('start_date', false, false)) / 1000;
        $event_startdate = new DateTime();
        $event_startdate->setTimestamp($event_startdate_raw)
        $event_startdate->setTimezone(new DateTimeZone(timezone_name_from_abbr('',  get_option('gmt_offset') * 3600, 0)));
        $event_startdate_jMY = $event_startdate->format('j M Y');

    Could anyone tell me how to make the package dates appear independent of the timezone that the editor is located, but based on the WP general settings?

  • Using built in WP settings and functions you cannot do this.

    It is especially difficult because you want this to work on the front end of the site and at this point there isn’t any way for PHP to know what editor set the time.

    The best solution that I can think of is to add a new field where the editor can select a time zone, like a select field, and have the values of this field match the format of the default time zone setting in WP. Then use this new field value to replace get_option('gmt_offset')

    You could limit the select field to only those values you need and have the default be where most of the editors are located.

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

The topic ‘Date Picker – Output changes depending on editor timezone?’ is closed to new replies.