Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Problem displaying the date in PHP?

I am have troubles displaying a date. I got the information from the database. Then I used the date() function.

This is how it looks:

$date = date('M j,Y' , $post_date);

the $post_date is from the database query

I defined it as $post_date = $row3['post_time'];

In the database I am using datetime for the post_time field

If you understand the mess I just said, do you know what I am doing wrong? And please show examples.

Update:

I did echo it, but when I did, it display Dec 31, 1969. The day should be Jul 9, 2010

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    What happens when you try to echo $date? Do you get an error? add error_reporting(0); to display all errors.

  • 1 decade ago

    If you run the code below, you will get the output: Dec 31, 1969

    $date = date('M j,Y' , -1);

    echo $date;

    which means that, $post_date is getting a value of -1.

    So, the problem is that your sql query is not returning any rows.

    And $post_date = $row3['post_time']; is giving you a value of -1

    Check you WHERE clause, and make sure that you are getting atleast 1 row back

Still have questions? Get your answers by asking now.