Jump to content

dd/mm/YYYY date problem


stevesimo

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.