WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
Datepicker Timestamps Incorrect (5 posts)

  1. pealo86
    Member
    Posted 2 years ago #

    I'm using a datepicker field and have set the value to '@' so that it outputs a Unix Timestamp.

    However the timestamps appear to be incorrect. If I select, for example, the 29th March 2012 it gives me the following:
    1332975600000

    Which, when converted (http://bit.ly/vLbBCh), gives me Sunday, February 5th 1984.

    Has anyone else had this issue?

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. mrwweb
    Member
    Posted 2 years ago #

    +1. Looking for help on this issue. ACF site is down right now, otherwise maybe I'd find some help there.

  3. mrwweb
    Member
    Posted 2 years ago #

    Figured it out. The above value is stored in milliseconds (I think) by the javascript date picker whereas PHP prefers seconds. So all you need to do is divide by 1000! (Thank goodness for stackoverflow.)

    Here's my code that worked:

    <?php echo date( 'F jS, Y', get_field( 'publish_date' ) / 1000 ); ?>

    This really should get worked into the ACF documentation, but hopefully others will find this answer here.

  4. ruhelamin
    Member
    Posted 2 years ago #

    Thanks for this... helped me out. Although for some reason my output date was off by 1 day so i added '+ 86400' in the calculation, which corrected it, thanks to a comment in the stackoverflow link by mrwweb.

  5. mrwweb
    Member
    Posted 2 years ago #

    @ruhelamin, glad that helped!

    With your off by one-day issue, try outputting the original value as a date and time to make sure that it's actually off by a full day (i.e. exactly 24 hours) and not some in-between amount. If it's anything other than 24 hours off, it's probably a time zone issue that you may want to resolve. Otherwise, adding that value may sometimes make the date wrong.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic