Support

Account

Home Forums ACF PRO Need help converting timestamps

Solved

Need help converting timestamps

    • Kracke

    • August 6, 2014 at 11:46 pm

    I’ve got a development install which I have upgraded to ACF Pro while making a host of other changes and we’ve “lost” our dates in ACF.

    The data is still there in a custom format the we used before (Ex. 2009-10-09), but I am unsure how to convert them all to the correct current format. I know that this can be resolved with a mySQL statement or two, but for the life of me, I’ve been unable to figure it out.

    Any help will be appreciated.

    • Elliot

    • August 7, 2014 at 2:36 pm

    Hi @kracke

    No worries. You can avoid having to modify the DB by adding some code to modify the value when it is loaded from the DB.

    The following code will remove the ‘-‘ from any datepicker values and allow the format to work with ACF PRO.

    
    add_filter('acf/load_value/type=date_picker', 'my_acf_load_value', 10, 3);
    
    function my_acf_load_value( $value, $post_id, $field ) {
    	
    	if( strpos($value, '-') !== false ) {
    		
    		$value = str_replace('-', '', $value);
    		
    	}
    	
    	return $value;
        
    }
    

    Hope that helps

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.