473,408 Members | 2,027 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,408 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 2250
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.