SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: date formatting
-
Oct 18, 2007, 12:05 #1
- Join Date
- Nov 2004
- Location
- Roxbury, NY
- Posts
- 107
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
date formatting
I have read dozens of posts, manuals, etc on date formatting. I know exactly how I want my date to be formatted and all of the various options I have for formatting the date.
But where do I put the information?
My query is
Code PHP://used for default display of tours by date mysql_select_db($database_atours, $atours); $query_tourDate = "SELECT * FROM tours, artists WHERE tours.artist_id=artists.artist_id AND date > NOW() ORDER BY date ASC"; $tourDate = mysql_query($query_tourDate, $atours); $row_tourDate = mysql_fetch_assoc($tourDate); $totalRows_tourDate = mysql_num_rows($tourDate);
The two dates I need to format are coded like this
Code PHP:<?php echo "<span class='tour-head'>"; echo $row_tourDate['date']; ?> <?php if(trim($row_tourDate['dateend']) != '0000-00-00'){ // print out everything echo " through "; echo $row_tourDate['dateend']; }else{ // don't do anything } ?>
I want to include date('M, d, Y').
I have also tried this in my query DATE_FORMAT(date, '%d %m %Y')
Just not sure where to put the info.
Your help is appreciated.Cherie
foamyindustries.com
Movies We Watch - we watch it and tell you what we think
chickenflicker.com - everyone needs a chicken a day
-
Oct 18, 2007, 13:09 #2
- Join Date
- Sep 2007
- Posts
- 136
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code PHP://used for default display of tours by date mysql_select_db($database_atours, $atours); $query_tourDate = "SELECT * FROM tours, artists WHERE tours.artist_id=artists.artist_id AND date > NOW() ORDER BY date ASC"; $tourDate = mysql_query($query_tourDate, $atours); $totalRows_tourDate = mysql_num_rows($tourDate); while($row_tourDate = mysql_fetch_assoc($tourDate)) { echo "<span class='tour-head'>"; echo $row_tourDate['date']; if(trim($row_tourDate['dateend']) != '0000-00-00'){ // print out everything echo " through "; echo $row_tourDate['dateend']; }else{ // don't do anything } } ?>
Post all you code cause I dont fully understand your problem
-
Oct 18, 2007, 13:12 #3
- Join Date
- Feb 2007
- Location
- UK
- Posts
- 591
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Is dateend a unix timestamp or a MySQL date?
For unix timestamp:
echo date('M, d, Y', $row['dateend'];
For MySQL date field:
echo date('M, d, Y', strtotime($row['dateend']));
(I think)
Edit:
PHP Code:if(trim($row_tourDate['dateend']) != '0000-00-00'){
// print out everything
echo " through "; echo $row_tourDate['dateend'];
}else{
// don't do anything
}
PHP Code:if(trim($row_tourDate['dateend']) != '0000-00-00'){
// print out everything
echo " through "; echo $row_tourDate['dateend'];
}
-
Oct 18, 2007, 13:29 #4
- Join Date
- Nov 2004
- Location
- Roxbury, NY
- Posts
- 107
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank You AlienDev. It nows works and I now understand how it works.
I am using dates pulled from the MySQL table. So echo date('M, d, Y', strtotime($row['dateend'])); works great.Cherie
foamyindustries.com
Movies We Watch - we watch it and tell you what we think
chickenflicker.com - everyone needs a chicken a day
-
Oct 18, 2007, 13:41 #5
Do the formatting within the SQL query itself:
http://dev.mysql.com/doc/refman/5.0/...on_date-format
DATE_FORMAT(date, '%d %m %Y') AS date
-
Oct 18, 2007, 14:18 #6
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Formatting your output in the SQL before passing it back to the PHP is more efficient and uses less code.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
Bookmarks