0

I am using wordpress for an integration with an recruitment software. Now i am having an issue with an 'endDate' slug. The date format seems to show up as yyyy-mm-dd. How can i change this format to dd-mm-yyyy

Here is the code i am using in the loop.php

<span class="closes-from">
            <?php
                    $post_meta_data = get_post_meta(get_the_ID());
                    echo ('Submission deadline: ').$post_meta_data['endDate'][0];
                    ?>
</span>

1 Answer 1

2

You will need to use strtotime() with Date() to make your own date format

If you already know the meta key that you need you can do the following

$post_meta_data = get_post_meta(get_the_ID(), 'endDate', true);

See get_post_meta for more information about the function.

Now that we have the value and going your format all you need to do is the following

$new_format = Date('d-m-Y', strtotime($post_meta_data));

EDIT

echoing the new format. I removed the ( ) because they are not needed for echoing string;

echo 'Submission deadline: ' . $new_format;

The whole code combined

<span class="closes-from">
    <?php
    // get end date (maybe change $post_meta_data to a more appropriate name)
    $post_meta_data = get_post_meta(get_the_ID(), 'endDate', true);

    // create a new date format
    $new_format = Date('d-m-Y', strtotime($post_meta_data));

    // output the new date format with some text
    echo 'Submission deadline: ' . $new_format;
    ?>
</span>
2
  • So how can i make it show up as the new format in the echo line?
    – Mo Bo
    Commented Feb 17, 2021 at 11:05
  • Updated my answer to include the output with the new date format Commented Feb 17, 2021 at 11:21

Your Answer

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

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