473,320 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Sort not working right?

My SQL statement isn't sorting right. I want to sort by date.

The table called 'news' has five columns:
id (autoincrement int)
published (date)
url (varchar)
title (varchar)
source (varchar)

The dates in the published column look like this: 2003-05-27

This the SQL statement (in PHP):
$query = "SELECT DATE_FORMAT(published,'%M %e, %Y') AS whatnot, url,
title, source FROM news ORDER BY whatnot";

The query result does not sort by the date. Can anyone tell me what's
wrong?

Thanks for your help.
Jul 19 '05 #1
2 2246
I think, the sorting takes places on the whatnot column wich could be
interpreted as a string, which has month before year, try ORDER BY
published, this way the internal save UNIX-Timestamp should be sorted.

"Bruce W...1" <br***@noDirectEmail.com> schreef in bericht
news:3F***************@noDirectEmail.com...
My SQL statement isn't sorting right. I want to sort by date.

The table called 'news' has five columns:
id (autoincrement int)
published (date)
url (varchar)
title (varchar)
source (varchar)

The dates in the published column look like this: 2003-05-27

This the SQL statement (in PHP):
$query = "SELECT DATE_FORMAT(published,'%M %e, %Y') AS whatnot, url,
title, source FROM news ORDER BY whatnot";

The query result does not sort by the date. Can anyone tell me what's
wrong?

Thanks for your help.

Jul 19 '05 #2
Too Sexy wrote:

I think, the sorting takes places on the whatnot column wich could be
interpreted as a string, which has month before year, try ORDER BY
published, this way the internal save UNIX-Timestamp should be sorted.

================================================== ===

Yes that fixed it. Thanks so much!
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bruce W...1 | last post by:
My SQL statement isn't sorting right. I want to sort by date. The table called 'news' has five columns: id (autoincrement int) published (date) url (varchar) title ...
40
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the...
12
by: Eva | last post by:
Hi, I try to implement quick sort. I sort vectors by their first value. 10 2 3 4 9 3 5 6 10 4 5 6 must be 9 3 5 6 10 2 3 4 10 4 5 6 The prog works great on maybe 500 vectors, but I have an...
3
by: Bob Dankert | last post by:
Is there any way to maintain the sort order of a sort on a 2D array? For example: I have the array: 1,a 2,a 3,f 4,a 5,s 6,a 7,z 8,b and sort it by the second column, and I...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
19
by: Derek Martin | last post by:
Hi there, I have been playing with sorting my arraylist and having some troubles. Maybe just going about it wrong. My arraylist contains objects and one of the members of the object is 'name.' I...
4
by: M Harvey | last post by:
I have an arraylist that contains datetime values. What is the best way to sort this arraylist by date ascending? Thanks, Matt
8
by: markww | last post by:
Hi, If I have a vector of structs like this: struct IMAGE { unsigned char *pPix; string strName; int nNumber; };
22
by: sandy | last post by:
I am trying to make a simulated directory structure application for a course. I am using a Vector to store pointers to my Directory objects (as subdirectories of the current object). In my...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.