User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,553 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,460 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 840 | Replies: 4 | Solved
Reply
Join Date: Oct 2007
Posts: 189
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Displaying dates in order

  #1  
Oct 17th, 2007
Hi there

I started a thread about this in the MySQL forum about this (http://www.daniweb.com/forums/thread93312.html).

Basically I don't know what my db table design should be like in order for me to sort the dates from most current to latest date.
The format is as follows:

DD Month YYYY eg(05 June 2007)

I was told a little while ago that there might be a way through php to spit the date out in the format shown above while having my table column set to DATE. If you know how that would help alot
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Location: Israel
Posts: 16
Reputation: Shaffer is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Shaffer Shaffer is offline Offline
Newbie Poster

Re: Displaying dates in order

  #2  
Oct 17th, 2007
Hello,
I have my table date/time column set to VARCHAR(40) for that matter, or anything above the length of the timestamp string.
Then, with PHP, I can get that information using date().

If you syntax is DD/MM/YYYY, you can explode the function by the forward slash (/), and then mktime(0,0,0,$date[1],$day[0],$day[2]), with $date being the result of the explode function above. Now, you have a timestamp that you can do whatever you want to with.

If you don't understand, I can present it in a code,
Shaffer.
Reply With Quote  
Join Date: Oct 2007
Posts: 189
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Re: Displaying dates in order

  #3  
Oct 17th, 2007
Originally Posted by Shaffer View Post
Hello,
I have my table date/time column set to VARCHAR(40) for that matter, or anything above the length of the timestamp string.
Then, with PHP, I can get that information using date().

If you syntax is DD/MM/YYYY, you can explode the function by the forward slash (/), and then mktime(0,0,0,$date[1],$day[0],$day[2]), with $date being the result of the explode function above. Now, you have a timestamp that you can do whatever you want to with.

If you don't understand, I can present it in a code,
Shaffer.

I am somewhat of a novice so an explanation with code would be great. Been racking my brain on this for the past couple of hours.
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Displaying dates in order

  #4  
Oct 17th, 2007
I think MYSQL can produce that format if you like.
you can use query like:

  1. <?php
  2. $query="Select day(datefield),monthname(datefield),year(datefield) from table";
  3. $result=mysql_query($query);
  4.  
  5. $day=mysql_result($result,0,"day(datefield)");//where 0 is the row you want to display..
  6. $month=mysql_result($result,0,"monthname(datefield)");
  7. $year=mysql_result($result,0,"year(datefield)");
  8.  
  9. $date=$day."-".$month."-".$year;
  10.  
  11. echo $date;
  12. ?>
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Oct 2007
Posts: 189
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Re: Displaying dates in order

  #5  
Oct 18th, 2007
Originally Posted by ryan_vietnow View Post
I think MYSQL can produce that format if you like.
you can use query like:

  1. <?php
  2. $query="Select day(datefield),monthname(datefield),year(datefield) from table";
  3. $result=mysql_query($query);
  4.  
  5. $day=mysql_result($result,0,"day(datefield)");//where 0 is the row you want to display..
  6. $month=mysql_result($result,0,"monthname(datefield)");
  7. $year=mysql_result($result,0,"year(datefield)");
  8.  
  9. $date=$day."-".$month."-".$year;
  10.  
  11. echo $date;
  12. ?>

Hi ryan

Thanks for your help. I managed to solve it with the following code:

$query = "SELECT heading, day(date), monthname(date), year(date), description FROM event ORDER BY date";
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
						
if (mysql_num_rows($result) > 0 )
{
  while($row = mysql_fetch_row($result))
  {
  echo "<p>".$row[0]."<br>".$row[1]." ".$row[2]." ".$row[3]."<br>".$row[4]."</p>";
  }
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC