WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] the_time() function will not capitalize

[Resolved] the_time() function will not capitalize

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

    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!

    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.

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] the_time() function will not capitalize’ is closed to new replies.
Skip to toolbar