Jump to content

Recommended Posts

Hi, I am working on an application which stores details of customer orders.  The payment date has been stored as a varchar in dd/mm/yyyy UK format ie. 28/10/2008.  My problem is that when I run a query on orders and try to index on payment date the results are not properly ordered.  I would normally store dates as a timestamp value but this system was written a couple of years ago and there are a lot of records already in the database.  Can anyone offer any advice on how I can get around this problem for the purposes of indexing the results in order of payment date using the existing dd/mm/yyyy varchar format. 

 

Thanks

 

Steve :)

Link to comment
https://forums.phpfreaks.com/topic/130427-ddmmyyyy-date-problem/
Share on other sites

SELECT *,STR_TO_DATE('paymentdate', '%d/%m/%Y') as pdate FROM table ORDER BY pdate

 

But you should really create a new field then do

UPDATE table  SET newfield = STR_TO_DATE('paymentdate', '%d/%m/%Y')

check it then remove the 'paymentdate' and rename 'newfield' to 'paymentdate'

 

;)

 

hope that helps

 

EDIT: backup before the update (i am not taking any blame if it goes wrong :P.. as you could probably find me in the UK *hide* )

but it should be fine

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.