Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STR_TO_DATE in mysql 4

Status
Not open for further replies.

hessodreamy

Programmer
Feb 28, 2005
59
GB
Is there an alternative to STR_TO_DATE which I can use in mysql 4.0?

I have some dates in the format 'August 24, 2004' and want to be able to order a query by that field.

Cheers
 
You could use something like:
[tt]
ORDER BY
RIGHT(datefld,4),
FIELD(
SUBSTRING_INDEX(datefld,' ',1),
'january','february','march','april','may',
'june','july','august','september','october',
'november','december'
),
LPAD(
SUBSTRING_INDEX(
SUBSTRING_INDEX(datefld,' ',-2),',',1
),
2,'0'
)
[/tt]
However, if it is at all possible to change the field to a DATE type, you should definitely do so. Having dates stored in that format is extremely inefficient.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top