Search code examples
sqldatecsvsqldatetime

Get the latest date in SQL from text format


I'm trying to get the latest date from a csv file , the dates are stored in this form

NOV 14 2010
FEB 1 2012
JUN 18 2014

and my query is like

SELECT Max(date) from table

I'm getting

NOV 14 2010

any idea ?


Solution

  • They are likely being considered strings(varchar) not DateTimes. Try:

    SELECT MAX(CAST(TABLE.date as DateTime)) FROM TABLE