![]() Topic awaiting preservation: Displaying the date (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: Greenville, SC, USA |
![]() Hello all, code: <?php //news Display page include ('config.php'); $newslist = mysql_query("SELECT id, DATA_FORMAT(newsdate,'%e %b %y') AS newsdate, newstitle, newstext FROM news"); if (@mysql_query($newslist)) { echo ('<p>So far so good, your news annoucement has been deleted!</p>'); } else { echo('<p>uh oh, what up with that?</p>' . mysql_error() . '<p>'); } while ($news = mysql_fetch_array($newslist)) { $newsid = $news['id']; $newsdate = $news['newsdate']; $newstitle = $news['newstitle']; $newstext = $news['newstext']; echo ('<h5>' .$newstitle. '</h5>' .$newsdate . '<p>' .$newstext. '</p>' ); } ?>
|
Maniac (V) Inmate From: under the bed |
![]() Not familiar with MySQL's date formatting capabilities - I always use PHP to format the date... |
Paranoid (IV) Inmate From: Greenville, SC, USA |
![]() How would you do it using php? |
Bipolar (III) Inmate From: Kansas City, MO , USA |
![]() echo date("j M y"); |
Paranoid (IV) Inmate From: Greenville, SC, USA |
![]() ok, I used the following: code: include ('config.php'); $newslist = mysql_query('SELECT * FROM news'); if (@mysql_query($newslist)) { echo ('<p>So far so good, your news annoucement has been deleted!</p>'); } else { echo('<p>uh oh, what up with that?</p>' . mysql_error() . '<p>'); } while ($news = mysql_fetch_array($newslist)) { $newsid = $news['id']; $newsdate = $news['newsdate']; $newstitle = $news['newstitle']; $newstext = $news['newstext']; echo ('<h5>' .$newstitle. '</h5>' . date($newsdate,'j M y') . '<p>' .$newstext. '</p>'); }
|
Maniac (V) Mad Scientist From: :morF |
![]() That's because, as far as I can tell, you're feeding a MySQL date into the date function, which is not how it works. It reads in Unix Timestamps and turns them into regularly formatted dates. if you want ot do it like that when you insert the news item in the first place you'll need to do code: "INSERT INTO news (newsdate) VALUES(".date().")"
code: $datetime_array = explode(" ",$news['newsdate']); $date_array = explode("-",$datetime_array[0]); $newsdate = mktime(0,0,0,$date_array[2],$date_array[1],$date_array[0]); unset($datetime_array); unset($date_array);
|
Paranoid (IV) Inmate From: Greenville, SC, USA |
![]() actually, did this: code: include ('config.php'); $newslist = mysql_query("SELECT id, DATE_FORMAT(newsdate,'%e %b %y') AS newsdateformatted, newstitle, newstext from news"); if (@mysql_query($newslist)) { echo ('<p>So far so good, your news annoucement has been deleted!</p>'); } else { echo('<p>uh oh, what up with that?</p>' . mysql_error() . '<p>'); } while ($news = mysql_fetch_array($newslist)) { $newsid = $news['id']; $newsdate = $news['newsdateformatted']; $newstitle = $news['newstitle']; $newstext = $news['newstext']; echo ('<h5>' .$newstitle. '</h5>' . $newsdate . '<p>' .$newstext. '</p>'); }
|
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
![]() yar you had DATA_FORMAT instead of DATE_FORMAT in your first post. |
Bipolar (III) Inmate From: f(x) |
![]() |
Paranoid (IV) Inmate From: Greenville, SC, USA |
![]() show me the UNIX_TIMESTAMP way of doing things. sounds interesting. |
Maniac (V) Inmate From: under the bed |
![]() http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html |