WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_time() function will not capitalize (5 posts)

  1. ruzel
    Member
    Posted 8 years ago #

    I would like to display the month in uppercase letters. I figured the easiest way to do that would be to use "strtoupper()" Here's what I've got running in the index.php template:

    <?php
    $tempdate = the_time('F');
    strtoupper($tempdate);
    echo($tempdate);
    ?>

    Alternately I've tried

    <?php
    strtoupper(the_time('F'));
    ?>

    but no dice.

  2. alrescha
    Member
    Posted 8 years ago #

    You need to use get_the_time() instead of the_time(). The former will return the time as a PHP string, allowing you to manipulate it further, then echo it out; the latter echos out the time directly.

    echo your_further_manipulation(get_the_time('format string'));

    The same goes for many of the other date and time functions.

  3. ruzel
    Member
    Posted 8 years ago #

    Not sure I understand the need for the difference but I'm sure it has to do with variable typing or something I don't understand--thank you so much!

  4. alrescha
    Member
    Posted 8 years ago #

    Those WordPress API functions with get_ prefixes will return a value, while their non-get_ counterparts simply output the value. Think of it this way:

    function two_plus_two() { echo 2+2; }
    function get_two_plus_two() { return 2+2; }

    This is the difference. If you skim through the Codex API documentation and compare, you'll see.

    The need for the difference is exactly to allow what you wanted to do here: to further manipulate the returned data, instead of throwing it straight out. Well, I'm not a developer so I actually wouldn't know exactly why they implemented these variations, but _I_ would implement these variations for the said reason.

  5. ruzel
    Member
    Posted 7 years ago #

    alrescha, thanks for that explanation. That was a subtlety in the function names that I had not noticed. And I agree with your reasoning, too.

Topic Closed

This topic has been closed to new replies.

About this Topic