0

i have a date column where dates are saved in varchar format like this
17-03-2011 :: 11:19:48

i want to find last date through query..

please help

thanks

3
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by pritaeas
0

Convert your varchar to a date and use ORDER BY DESC, or GROUP BY and MAX()

Edited by pritaeas: n/a

0

sorry i cant change the database. is there anyway to explode date format in mysql.

0

Cast() function..???? :O

didnt get any such function

0
SELECT `field1`, `field2`, STR_TO_DATE(`datefield`,'%d-%m-%Y :: %h:%i:%s') AS mydate FROM `table1` ORDER BY mydate;

Don't know if that will work. Can you order on the calculated field?? Sorry brain frazzled.

Edited by diafol: n/a

0

I think you need to do:

SELECT STR_TO_DATE(`datefield`, '%d-%m-%Y :: %h:%i:%s') AS mydate
FROM `table1` 
ORDER BY STR_TO_DATE(`datefield`, '%d-%m-%Y :: %h:%i:%s') DESC LIMIT 1

Edited by pritaeas: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.