I have a custom field to store the date of games, and I store it in database like


Now I need to convert all dates to


So how can do that?

Is timestamp a solution for it, if yes, how can do that

I need to change all old data to new data for 200 posts

  • Are you talking about custom fields? If so, you should store dates as yyyy/mm/dd Feb 29, 2016 at 10:45
  • yes, before i store as yyyy/dd/mm but now i change it to yyyy/mm/dd, but old data i need to change it
    – AbuKotsh
    Feb 29, 2016 at 10:50
  • Use date() in conjunction with strtotime(). Click
    – dingo_d
    Feb 29, 2016 at 10:50
  • @dingo_d how can change old data ?
    – AbuKotsh
    Feb 29, 2016 at 10:52
  • $new_date = date('d/m/Y', strtotime($old_time));, where $old_time is the value of your date from where ever you are pulling it from (database I presume).
    – dingo_d
    Feb 29, 2016 at 10:57

1 Answer 1


Find the correct key for game_date_key and run this once:

global $wpdb;
$posts = $wpdb->get_results("SELECT ID FROM ".$wpdb->prefix."posts" WHERE post_type='post');
foreach ($posts as $post) {
    $old_date = get_post_meta($post->ID,'game_date_key',true);
    $new_date = date('d/m/Y', strtotime($old_date));

(I assume you will have the sense to backup your database first just in case. :-)

  • nice.. but some time i store in mm/dd/yyyy what can i do ?
    – AbuKotsh
    Feb 29, 2016 at 18:22
  • pick one format and stick to it (the new is more international), you can always convert it back a similar way after retrieving it if need be.
    – majick
    Mar 1, 2016 at 1:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.