Forums

Extract the_time() as string (5 posts)

  1. magicwings
    Member
    Posted 7 months ago #

    Hey all,

    Basically I'm trying to get a string attached to the_time('F j, Y').

    What's going wrong?

    My code is this (for example):

    <?php $my_post_date = the_time('F j, Y') ?>

    BUT on ANY mention of the function the_time(), it will ECHO what I've written!

    This means that the above actually APPEARS on the page saying

    October 9, 2011

    despite me just trying to declare it as part of the $my_post_date string.

    So how do I make a string that has the posts' date? Any ideas?

  2. peredur
    Member
    Posted 7 months ago #

    See http://codex.wordpress.org/Function_Reference/the_time:

    Codex

    Function Reference/the_time

    Displays the time of the current post. This tag must be used within The Loop.

    The operative word here is "Displays".

    Use the PHP date() function or one of its many friends.

    HTH

    PAE

  3. magicwings
    Member
    Posted 7 months ago #

    Ah, but I'm trying to get the date of the current post within the loop, and compare it with today's date.

    How's that possible?

  4. peredur
    Member
    Posted 7 months ago #

  5. magicwings
    Member
    Posted 7 months ago #

    Awesome, thanks, worked a charm :)
    Ben

Reply

You must log in to post.

About this Topic