3

I have trouble converting Unix timestamp (i.e. 1473897600) to Wordpress friendly date which displays at the date input field. I have a frontpage, post edit panel which is showing Unix timestamp.

I guess this is the code for getting the post's date;

<?php   $post_to_edit = array();
        $post_to_edit = get_post($_POST['postid']); 

        $date = $_POST[ '_single_date' ];   ?>

And editing and updating the date with following code works fine;

update_post_meta($pid, '_single_date', strtotime($date) ); 

date input field;

<input value="<?php echo get_post_meta($post_to_edit->ID, '_single_date', true); ?>" name="_single_date" />

1 Answer 1

6

You should use date_i18n():

$timestamp = get_post_meta($post_to_edit->ID, '_single_date', true);

$friendly_date = date_i18n( get_option('date_format'), $timestamp );

?><input value="<?= $friendly_date ?>" name="_single_date" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.