How to format wordpress post date

Changing wordpress post or custom post date format is very easy. If you are using WP_Query and using while loop you can format the date with this

<?php echo date('l, F j, Y', strtotime(get_the_date())) ?>
Output will be "Friday, September 24, 2004"

If you are using get_posts() function and using foreach loop code will be like this

<?php echo date('l, F j, Y', strtotime($post->post_date)) ?>

Here are some example of formats

Format String Examples

Here are some examples of date format with the result output.

  • F j, Y g:i a – November 6, 2010 12:50 am
  • F j, Y – November 6, 2010
  • F, Y – November, 2010
  • g:i a – 12:50 am
  • g:i:s a – 12:50:48 am
  • l, F jS, Y – Saturday, November 6th, 2010
  • M j, Y @ G:i – Nov 6, 2010 @ 0:50
  • Y/m/d \a\t g:i A – 2010/11/06 at 12:50 AM
  • Y/m/d \a\t g:ia – 2010/11/06 at 12:50am
  • Y/m/d g:i:s A – 2010/11/06 12:50:48 AM
  • Y/m/d – 2010/11/06