1

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?

1

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.

  • 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 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.