Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

i have a table in which i have a varchar column which stores date of some events. is ther any way to get the maximum and minimum dates from that column using mysql Query.
its a very old table and it contains so many records , i cant modify the schema and all since it is also used in some other applications.
dates are stored in dd-MMM-yyyy format
thank you
Posted
Updated 30-May-15 0:58am
v2

1 solution

Hi,

You can use "IsDate" function of SQL to check whether the string is in proper date format or not.

Can you please try with below query ?

VB
SELECT MAX(T.DATE)
FROM (
    SELECT CASE
            WHEN ISDATE(YourDate) = 1
                THEN CAST(YourDate AS DATE)
            ELSE NULL
            END AS DATE
    FROM YourTable
    ) T


Please let me know if you have any concern or query on this.

Thanks
Advay Pandya
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900