Solved

Sort date style month.day.year

Posted on 2004-08-04
2
812 Views
Last Modified: 2011-09-20
I am looking for help on sorting dates with mysql. Here is a query that I am working with:
$result = mysql_query("select * from shows ORDER by showdate");

This is working but not as I need it to. Here is a sample date systen I want to use:
month.day.year
03.17.04
08.13.04
11.14.04
01.23.05

How can I set up mysql to work with this date system? Note - I am working with PHPAdmin so if you can speak to me in that lingo it would be helpful because I am not fully versed with mysql command prompt. Also does it matter if I use "/" or "." to separate the month.day.year

Thanks
0
Comment
Question by:waffe
2 Comments
 
LVL 7

Accepted Solution

by:
madwax earned 100 total points
ID: 11721749
Hi waffe,

I would recommend you saving your dates as timestamps since that will give you the most possible functionality. Namely, a timestamp is a integer which is easy to save, and both PHP and MySQL have built-in functions for dealing with timestamps.

E.g.

1. then you can php to output your timestamp as: <?=date("m.d.y",$timestampFromDB?> where you may change the "m.d.y" to whatever you want by to get _ANY_ output. See: http://se.php.net/manual/en/function.date.php

2. MySQL has the built-in function FROM_UNIXTIME() which you can use as well: See:
http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html

Feel free to ask more if you don't belive me... :)

Regards,
//madwax


0
 
LVL 17

Assisted Solution

by:akshah123
akshah123 earned 50 total points
ID: 11721755
Instead of
$result = mysql_query("select * from shows ORDER by showdate");

try

$result = mysql_query("select * from shows ORDER BY DATE_FORMAT(showdate, '%m/%d/%Y')");
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question