Max of month year Mysql/PHP -
here sql table
| id | info | date | |----|-----------|----------------| | 1 | info | oct 2014 | | 2 | info | september 2014 |
and want fetch latest month year in table since date varchar how max date out ?
this should it:
select max(str_to_date(date, '%m %y')) max_date schema.data;
here's tested php example:
<?php function getmaxdate() { seek { $db = new pdo("mysql:host=localhost;charset=utf8", "root", "root"); $cmd = $db->prepare(" select max(str_to_date(date, '%m %y')) max_date schema.data; "); $cmd->execute(); $result = $cmd->fetch(); homecoming $result[0]; } grab (pdoexception $e) { echo $e->getmessage(); return; } } echo getmaxdate(); ?>
returns following:
2014-10-00
php mysql sql mysqli
No comments:
Post a Comment