WordPress.org

Ready to get started?Download WordPress

Forums

Simple PHP Date + Math question (3 posts)

  1. petezarustica
    Member
    Posted 3 years ago #

    Hi everybody,

    I want to write someone's age and I want it to be dynamic. So let's say Julie is 20 years old. Then Julie is (this year - 1981) years old.

    I manage to do that calculation on WP with the following code:

    <?php $prodid = 2011;
    $second_number = 1991;
    $sum_total = $prodid - $second_number;
    print ($sum_total);
    ?>

    But it's still not dynamic - I'd like the 2011 to be <?php the_time('Y'); ?> but it's doesn't work!!! ^
    Can someone help me with this detail?

    [s]

  2. Andrei Olsen
    Member
    Posted 3 years ago #

    $prodid = strftime('%Y');

    http://php.net/manual/en/function.strftime.php

    or better yet:
    http://www.php.net/manual/en/function.idate.php

    print(idate('Y')-$second_number);

  3. petezarustica
    Member
    Posted 3 years ago #

    Thanks Andrei! :)

Topic Closed

This topic has been closed to new replies.

About this Topic