Support » Theme: Atahualpa » How do I compare dates?

  • Hello, I want to compare date-modified and date on the Post Info Items page. What I actually have is this:

    %date('j F Y')% - updated %date-modified('j F Y')%

    Now, if the 2 dates are equal, I dont want to display – updated %date-modified(‘j F Y’)%. How can I do this?


Viewing 5 replies - 1 through 5 (of 5 total)
  • You need to write a bit of PHP (AFAIK). Does this help:

    PHP date comparison

    This next line might help you to understand what’s going on behind the scenes with the code you posted:

    PHP date() function

    Basically, what I’d be looking at (on a first look) would be to convert the date strings to timestamps, compare them and then conditionally echo the date-modified string. Somebody else might know of a better way, or even of some WP specific functions. I confess I didn’t look to see if there were any.

    That’s something else you might consider, of course, which is to write a function for this in the functions.php file for your theme.




    Hello, thanks for the reply. PHP is not the problem, the problem is that I dont know how to access %date(‘j F Y’)% or %date-modified(‘j F Y’)% inside the PHP code snippet? Once thats clear I might compare the resulting types, thats true.

    Ideas? Thanks 🙂



    Where are you seeing the string you quote? What page? And what theme are you using?

    WP has some functions like get_the_modified_date() the_modified_date() and the_date() at least. There may be others.

    Have you looked in your theme’s functions.php file to see if the functions are there?

    I have to say, I don’t immediately recognise what’s going on with the percent signs, but if you can give me an idea of where to find the code I’ll have a go at working it out.



    I am using Atahualpa and in the description it says:

    %date(‘F jS, Y’)% – Display the date and/or time the post was published at.

    %date-modified(‘F jS, Y’)% – Same as above but displays the post’s last modfied date instead of its creation date.

    I can put those in a textbox under the menu point Edit Post/Page info items. I guess it replaces those values with the real PHP functions. I can post PHP in those textboxes as well. Entering

    <?php echo "Hello world!"; ?>

    for example really prints “Hello World”. So the question is what do I put inside the <?php …?>.

    Thanks 🙂

    Well, this might give some clue:

    Without any context, it’s hard for me to imagine what’s going on, but as far as I can see, the regex just strips off the ‘%’ signs so you’re left with a call to the original function.

    Perhaps you could post something like half a dozen lines around the code you’re quoting so I can get a better idea of what’s happening?

    Either that or just replace the whole of the code with the appropriate PHP and WP date and time functions (all of which I referred to in previous posts). WP functions to get the dates and times: PHP functions to do the Maths. I think you’ve already said that PHP isn’t a problem for you.

    I hope you’re doing this in a child theme BTW. Messing with the theme code itself is probably not such a good idea, especially when child themes are so easy. Assuming the theme is child theme friendly, of course. If not, you probably need to copy the whole theme, rename it, activate it and work on the renamed theme: but you’ll miss out on updates and bug fixes, of course, if you don’t use a child theme.

    Anyway, it doesn’t sound to me as though what you want to do is so hard. You’re just wanting to conditionally output some text, after all.



Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I compare dates?’ is closed to new replies.