0

In author archive, I want to show author registration date in the following format:

January 16, 2021

I have found this code:

$user_ID = $post->post_author;
echo the_author_meta( 'user_registered', $user_ID );

But its output format is:

2021-01-16 10:40:52

How can I strip off time and get my desired format?

I am using date format F j, Y

1

How about reformat it instead of stripping?

//Get post author ID
$post_author_id = get_post_field( 'post_author', $post->ID );

//Get the registration date
$registered_date = get_the_author_meta( 'user_registered', $post_author_id );

//Convert to desired format
$output = date( 'F j, Y', strtotime($registered_date));

//Echo
echo $output;
4
  • Your code is outputing this: 2021-01-16 10:40:52January 1, 1970 Have you checked the code? – Morshed Alam Sumon Apr 19 at 8:53
  • It shouldn't. Check if you already has your previous code enabled and is outputting the numeric date, i.e 12021-01-16 10:40:52. – Abhik Apr 19 at 8:57
  • Anyway, just fixed a typo. Check now. – Abhik Apr 19 at 9:00
  • it works! Thank you very much. – Morshed Alam Sumon Apr 19 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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