Support » Plugins » Using the_time() as the input for a different function

  • I am trying to use the output from the function the_time() (the time stamp) as input for a function that replaces it.
    In other words, instead of using the_time() to display the time stamp on my page, I want to use my_function(), which takes the output from the_time() and then displays the time in a different format.
    Unfortunately, I don’t know enough about PHP & WordPress to work out how to take the output from the_time() and use it in my_function(). my_function() needs the time as a string, but I’m not sure what format the_time() produces and how to use it in my_function(). I’ve tried my_function(the_time()) but that doesn’t work.

    So my question is: how do I get the_time() to output a string that I can use in a function?

    Thanks in advance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m guessing here based on what I’ve seen (e.g. I didn’t test this): the_time() probably outputs the time based on the blog settings under Options, General. Those settings use straight PHP date/time formatting syntax. You might not need your own function. Instead you might be able to just tweak those settings. Go to and look up “date” or “time” (I forget which) and you’ll find a long list of codes you can use. For example (this I do remember because I use it): “j M d” would show 22 Mar 06.

    I know what you mean, but that’s not the problem 🙂
    My function takes the time in a specific format (that I’ve specified in the Options as you say), and turns it into a phrase like “ten past four” instead of the timestamp “4:10”.

    What I need is a way of passing the “4:10” from the_time() to my own function.

    Try this :

    my_function( the_time() ) ;

    Then parse the string received in my_function:

    function my_function($my_time_string) {

    […string parsing code that acts on $my_time_string…]


    Looks like this guy might have already written some useful code:

    I believe marke1 meant:

    my_function( get_the_time() ) ;

    get_the_time() returns the time instead of echoing it.

    I simply copied the function as written by the original poster…

    I was aware of that marke1. But as it doesn’t work as is, I felt it important to note what would… ;)

    Awesome! I used:
    my_function( get_the_time() ) ;
    and it works perfectly. Thanks guys 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using the_time() as the input for a different function’ is closed to new replies.