Topic awaiting preservation: Displaying the date |
|
---|---|
Author | Thread |
Paranoid (IV) Inmate From: Greenville, SC, USA |
posted 10-01-2005 22:16
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 |
posted 10-01-2005 23:23
Not familiar with MySQL's date formatting capabilities - I always use PHP to format the date... |
Paranoid (IV) Inmate From: Greenville, SC, USA |
posted 10-02-2005 02:28
How would you do it using php? |
Bipolar (III) Inmate From: Kansas City, MO , USA |
posted 10-02-2005 03:14
echo date("j M y"); |
Paranoid (IV) Inmate From: Greenville, SC, USA |
posted 10-02-2005 03:48
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 |
posted 10-02-2005 13:21
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 |
posted 10-02-2005 15:10
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 |
posted 10-02-2005 21:45
yar you had DATA_FORMAT instead of DATE_FORMAT in your first post. |
Bipolar (III) Inmate From: f(x) |
posted 10-02-2005 22:05 |
Paranoid (IV) Inmate From: Greenville, SC, USA |
posted 10-03-2005 17:13
show me the UNIX_TIMESTAMP way of doing things. sounds interesting. |
Maniac (V) Inmate From: under the bed |
posted 10-03-2005 18:06
http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html |