SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
Thread: displaying date
-
Jan 15, 2001, 14:32 #1
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Howdy all,
I am pulling dates from mysql in yyyy-mm-dd format. I would like to display them in another format, either mm.dd.yyyy or month name, dd, yyyy.
I found the below script and it would work, but I have 5 "updates" being displayed on one page and I don't want to interfere with the display of the content. View http://www.plusoneonline.com/home to see what I am talking about.
Code:$date = "2000-12-11"; $temp = explode("-", $date); $year = $temp[0]; $month = $temp[1]; $day = $temp[2]; print date ("l, F jS, Y", mktime (0,0,0,$month,$day,$year));
Code:<?php $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (!$conn) { echo "<P>Unable to connect to the database server at this time.</P>"; exit(); } if (! @mysql_select_db($dbname) ) { echo( "<P>Unable to locate the database at this time.</P>" ); exit(); } $result = mysql_query("SELECT date, content FROM po_updates ORDER BY date DESC LIMIT 5;"); if (!$result) { echo "<P>Error performing query on database"; exit(); } while ($row = mysql_fetch_array($result)) { echo "<span class=\"divider\" width=\"100%\">"; if ($row["date"] > 3) { echo "<img src=\"../images/image_new.gif\" width=\"30\" height=\"15\" border=\"0\" align=\"left\">"; } echo " ".$row["date"]."</span><br><br>"; echo $row["content"]; echo "<br><br>"; } ?>
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 15, 2001, 14:58 #2
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yep, I was using a similar method until I discovered this method, courtesy of FreddyDoesPHP
$result = mysql_query("SELECT DATE_FORMAT(datefield, '%M, %D, %Y') as something, content FROM po_updates ORDER BY date DESC LIMIT 5;");
you can then access it by using $row["something"]
You can change the format by using these entities...
%M Month name (January..December)
%W Weekday name (Sunday..Saturday)
%D Day of the month with english suffix (1st, 2nd, 3rd, etc.)
%Y Year, numeric, 4 digits
%y Year, numeric, 2 digits
%a Abbreviated weekday name (Sun..Sat)
%d Day of the month, numeric (00..31)
%e Day of the month, numeric (0..31)
%m Month, numeric (01..12)
%c Month, numeric (1..12)
%b Abbreviated month name (Jan..Dec)
%j Day of year (001..366)
%H Hour (00..23)
%k Hour (0..23)
%h Hour (01..12)
%I Hour (01..12)
%l Hour (1..12)
%i Minutes, numeric (00..59)
%r Time, 12-hour (hh:mm:ss [AP]M)
%T Time, 24-hour (hh:mm:ss)
%S Seconds (00..59)
%s Seconds (00..59)
%p AM or PM
%w Day of the week (0=Sunday..6=Saturday)
%U Week (0..52), where Sunday is the first day of the week
%u Week (0..52), where Monday is the first day of the week
%% A literal `%'.
<Edited by PeterW on 01-15-2001 at 03:11 PM>
-
Jan 15, 2001, 15:05 #3
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Peter, did you mean to have 2 SELECT's in your statement?
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 15, 2001, 15:11 #4
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Weird!!!
Using this statement
SELECT DATE_FORMAT(date, '%m.%d.%Y') as date, content FROM po_updates ORDER BY date DESC LIMIT 5
I don't get any of the updates I have in my DB for January 2001. I only get the ones dating back to the end of December.
I have the datestamp entered in the DB as yyyy-mm-dd.
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 15, 2001, 15:13 #5
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
lol no
I think it is because it will be now order by month.day.year, so the highest months will come first..
Thus, use something different to "date".
-
Jan 15, 2001, 15:13 #6
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Another weird thing is that statement that I listed above works on my PHP page, but it does not work when I type it into the query field in phpMyAdmin 2.1.0.
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 15, 2001, 15:14 #7
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
is there way to ordet the dates first and THEN change them?
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 15, 2001, 15:17 #8
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Peter ...never mind about that. I entered them into the DB in chronological order with an ID field so I will sort on the ID field.
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 15, 2001, 15:22 #9
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
or could you just select the date as a different name like prettyd?
<edit>Sounds just as good.. bit more hassle though</edit>
Peter
-
Jan 15, 2001, 15:25 #10
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
actually, it was no more hassle. I just tried it and it works. That is more reliable anyway. Thanks Peter.
enjoy your KarmaAdobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
Bookmarks