WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a date on each post and comment which shows the date of placement.

If I edit it, it shows me the date of the post and the modified date. That's fine, but now, I want to show only the post date AND the TIME of the modified date only if the post is edited on the same day as it's posted.

So for example:

If a post is has been submitted on 8 march 2013 15:00, show me: 08-03-2013 15:00
If a post is edited on 8 march 2013 16:30, show me: 08-03-2013 15:00 - 16:30
If a post is edited on 9 march 2013 17:00, show me: 08-03-2013 15:00 - 09-03-2013 17:00

How can I do this? I am using something like this, except for the AM and PM.

<?php the_modified_date('F j, Y'); ?> at <?php the_modified_date('g:i a'); ?>

How can I only show the time if it's modified on the same date?

share|improve this question

Give this a try:

if(get_the_modified_date('zY')==date('zY')) {  
the_modified_date('g:i a'); 
} else {
the_modified_date('F j, Y'); echo ' at '; the_modified_date('g:i a');

It checks that the modified date is the current day. If it is, it only displays the modified time. Otherwise it displays both the date and time.

share|improve this answer
Hi Alex, how can I add that in this one? It is already in a if statement. How do I do that? <div class="info"><a href="%1$s" rel="bookmark">#'.get_the_ID().'</a> <time datetime='. get_the_date('d-m-Y') . '>%3$s '.get_the_time( $d, $post ).'</time> – Johan Jul 28 '13 at 17:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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