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: 
I am not sure why you would want to keep it as varchar not date.
But this will work for varchar:

```
SELECT completion_date
FROM test
ORDER BY STR_TO_DATE(completion_date, '%m/%d/%Y') DESC LIMIT 1;

```

<http://sqlfiddle.com/#!9/c88f6/10>
```
<?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.