Jump to content

ORDER BY....


marco-marco

Recommended Posts

When i use the following code, in order to ORDER BY dateStart, it orders by the day due to using date format.

ie:

18-01-2005

19-03-2004

27-12-2005

 

is there anyway to order by the the year month then day in this date format?

 

DATE_FORMAT(dateStart,\'%d-%m-%Y\' )AS dateStart,

DATE_FORMAT(dateEnd, \'%d-%m-%Y\')AS dateEnd

ORDER BY dateStart 

Link to comment
Share on other sites

Ok, you can then order by that column without applying any type of format. Formatting is converting the column to a string, and it\'s underlying format is an integer which will intrinsically sort as you would expect. If you want to format the columns for display, that is not a problem and can be done seperately from the order by, which is to say that you can have columns in your order by that are not in your select list.

 

In your example, simply use a different alias for your formatted date, rather than re-aliasing the original column name and all should work as you want it to.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.