The MU forums have moved to WordPress.org

how to convert a date (4 posts)

  1. Melodiefabrieknl
    Member
    Posted 17 years ago #

    This is the date I am selecting from my database, table WP_1_posts:

    2006-12-07 04:48:12

    when I do an echo using the function date($tmp_post_date) this is shown:

    2006-12-07 04:48:12

    this is correct, this date I can find in the database as well

    but when I want to format the date, using the date function, date("Y/m/d",$tmp_post_date) I get this on the screen:
    1969/12/31

    Why? What am I doing wrong?

    Can someone help please? I guess my php skills are way below...

  2. lunabyte
    Member
    Posted 17 years ago #

    It has to do with the format of the string. It's a mysql datestamp, vice a unix time string.

    Try using the_time(options) instead, if you're inside the loop, or try this outside of it:

    date( "Y/m/d", strtotime($tmp_post_date) )

    strtotime will take the mysql date, and turn it into a timestamp, for use by the date function.

  3. Melodiefabrieknl
    Member
    Posted 17 years ago #

    Yes, that makes sense. Great one, thanks!

  4. lunabyte
    Member
    Posted 17 years ago #

    You're welcome.

About this Topic

  • Started 17 years ago by Melodiefabrieknl
  • Latest reply from lunabyte