Jump to content

SQL order by dates


swamp

Recommended Posts

Hi there,

 

I have dates in this format in my database:

 

dd.mm.yy

 

So today would be 24.02.09

 

I know this may not be the correct way of entering them but they have been transfered like this and there are 6000+ entries.

 

How could I order them by date descending and leave them in the current format?

 

Thanks in advance!

Link to comment
Share on other sites

I do not think you can....that is just a bad designed DB.

 

MySQL Date Functions

 

About all I could think is you can try the MakeTime function, or the STR_TO_DATE function and see if they allow you to convert it to a good date format to sort by.

 

 

To fix this issue at it's source, you should be able to create a new date column, which will store a new date and be of DATETIME and use that str_to_date function to convert the current date to a good date and update it.

 

If that does not work, you can pull it out in php explode the date at the "." then re-create it in a good date format and input it back into the DB so you have the correct format and not have to do this "hack" to get your sql to sort by date.

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.