Question: I need to find max date from a table(mysql database). I am storing my date as varchar.

`select max(completion_date) from table_name` returns wrong value.

<http://sqlfiddle.com/#!9/c88f6/3>

Answer: 
Assuming the date time format you have in your fiddle (e.g. '12/19/2012 05:30 PM') then:

```
select max(STR_TO_DATE(completion_date, '%m/%d/%Y %l:%i %p')) from test;

```

<http://sqlfiddle.com/#!9/c88f6/15>

It's unclear if you want to factor the time into your rankings or just the date. This example accounts for time too, but you can remove that part of the formatter if desired.
```
<?php
  // Store dates
  $dates = array();
  // Loop through and transfer the result set
  foreach ($result as $row => $data) {
    $dates[$row] = $data['date'];
  }
  // Sort the array
  usort( $dates, "date_sort_function" );
  // Max is last date in array.
  foreach ($dates as $date) {
    $max = $date;
  }
?>

```

Well, something like that. It is a php script and all you have to provide is the sorting function which returns 0 if equal, 1 if older, and -1 if earlier.