LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-30-2011, 07:15 AM   #1
Prosaca
LQ Newbie
 
Registered: Apr 2011
Posts: 4

Rep: Reputation: 0
[MySQL] Order by custom Date


Hello. I'm actually tryinng to order all by DATE on MySQL but seems not to be possible.

The date order is like this for example: Wednesday, June 29, 2011, 18:31

I tried with this, but doesn't work:
SELECT * FROM members ORDER BY date ASC
Sometimes it works with DESC.

And also with this, and same!
SELECT * STR_TO_DATE( date, '%D, %M %d, %Y, %H:%M' ) AS date_for_sort FROM `members` ORDER BY date_for_sort;


I have this problem and I need to fix it asap for the business.

Thank you for helping,
keep the good work!
 
Old 06-30-2011, 09:14 AM   #2
opnsrc
LQ Newbie
 
Registered: Dec 2005
Posts: 28

Rep: Reputation: 1
It would depend on what type the date field was originally created as when the table was created. I have a hunch that it's simply a character (char) based field with XX amount of space. That would render your second approach where you're attempting to STR_TO_DATE useless as a char field won't know those values. Do a 'SHOW columns from members;' and you'll see the assigned value.
 
Old 06-30-2011, 09:23 AM   #3
fbianconi
Member
 
Registered: Apr 2008
Location: argentina
Distribution: Arch
Posts: 86

Rep: Reputation: 22
I think the consult should look like this

SELECT * STR_TO_DATE( date, '%W, %M %d, %Y, %H:%i' ) AS date_for_sort FROM `members` ORDER BY date_for_sort;

a reference to formats of dates can be found here

Last edited by fbianconi; 06-30-2011 at 09:24 AM. Reason: typo
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] MYSQL select ORDER BY, GROUP BY together sqn Programming 5 04-19-2010 06:07 AM
grep a directory with date order ust Linux - Newbie 4 02-16-2009 02:17 AM
Make mysql order by to behave differently raven Linux - Server 2 11-30-2007 03:33 AM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 08:43 AM
[PHP+MySQL] Rotate order in SELECT pnh73 Programming 5 12-31-2003 04:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration