WordPress.org

Ready to get started?Download WordPress

Forums

Using the_time() as the input for a different function (8 posts)

  1. roland_ob1
    Member
    Posted 8 years ago #

    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.

  2. marke1
    Member
    Posted 8 years ago #

    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 php.net 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.

  3. roland_ob1
    Member
    Posted 8 years ago #

    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.

  4. marke1
    Member
    Posted 8 years ago #

    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:

    http://drnoble.co.uk/code/about_ago.phps

  5. Kafkaesqui

    Posted 8 years ago #

    I believe marke1 meant:

    my_function( get_the_time() ) ;

    get_the_time() returns the time instead of echoing it.

  6. marke1
    Member
    Posted 8 years ago #

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

  7. Kafkaesqui

    Posted 8 years ago #

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

  8. roland_ob1
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic