Support

Account

Home Forums ACF PRO Migrating from timestamp to Date Field

Solved

Migrating from timestamp to Date Field

  • Hello,

    I have some custom meta I’ve built in the past to manage members of a team.
    Now in order to add more flexibility , I would like to migrate this stuff to ACF (I’m very familar with this plugin and want to deploy it to all my CPTs).

    But something makes me crazy for managing date.

    The meta I used for the birthdate was a timestamp and I wanted to migrate it to a date field under d/m/Y format.

    ACF PRO saves date under Ymd format, so I change all my timestamps to a Ymd formatted string.
    But when I try to use get_field on this migrated values, it does not work and I can not display them in a Date field under my UI. Echoing this value shows that ACF reads the value but does not interpret it as a date…

    Where Am I wrong ?

    Any help appreciated.

    Thanks

    Christian

  • Using update field does not work for date (it works for string).
    So the solution I’ve put in place is :

    
    $this->birthdate = date( "Ymd", $this->birthdate );
    update_post_meta ($this->ID, 'birthdate',  $this->birthdate);
    update_post_meta ($this->ID, '_birthdate', 'field_53e11dd3841f6'); // CONSTANT KEY
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.