Re: Ordering by dates

From: Date: Sun, 12 Nov 2000 11:34:46 +0000
Subject: Re: Ordering by dates
Groups: php.general 
Request: Send a blank email to php-general+get-24850@lists.php.net to get a copy of this message
Addressed to: tyler.longren@midiowa.net "PHP-General" <php-general@lists.php.net> ** Reply to note from "Vijest.com" <slaven.vujic@vijest.com> Sat, 11 Nov 2000 08:55:52 +0100 The first thing you (Tyler) should do is get rid of those wierd dates, and use either separate DATE and TIME fields, or a single DATETIME field which would be more efficient. Once the fields are in a format the database understands the data in the field, it is easy. ORDER BY DateField If you don't do that, you are going to have to zero fill the month and day parts of the date field before you compare them. It can be done, but it is not worth it! There is no problem displaying them any way you want, just look for DATE_FORMAT in "functions for use in SELECT and WHILE" section of the MySQL Manual. It is part of Chapter 7, the language reference. http://www.mysql.com/documentation/mysql/commented/ > > > There are also many MySQL date/time functions, so you might find it > usefull to look at MySQL manual. I think the best way to do that is using > TIMESTAMP. > > lancelot_ > > At 23:18 2000.11.10 -0600, Tyler Longren wrote: > >Hey list, > > > >How would I order the following by date. The dates are in mm-dd format > >(Eg: 11-10). This is a problem when trying to order the events by their > >date. Here's a snippet of mysql table: > > > >sport location date time opponent > >-------------------------------- > >Football Maxwell 9-20 7:30 Colo-Nesco > > > >Football Baxter 10-13 7:30 North Polk > >Football Collins 10-1 7:30 West Marshall > > > > > >Now, is there anyway I could order these by date. A simple > >mysql_query("SELECT * FROM sports WHERE sport = '$sport' ORDER BY date > >ASC"); > >doesn't exactly work. I suppose it's because of the date format. Would > >this be easier to convert the dates to timestamps? Any ideas would be very > >very much appreciated. > > > >Thanks! > >Tyler Longren > > > >Just for some background info, this is a project for school. It's a > >listing of sporting events for my school. Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.general (#24850) next »