Uso la seguente funzione per convertire il normale valore data-ora in formato datetime mysql
private function ampmtosql($ampmdate) {
if($ampmdate == '')
return '';
$ampm = substr(trim(($ampmdate)), -2);
$datetimesql = substr(trim(($ampmdate)), 0, -3);
if ($ampm == 'pm') {
$hours = substr(trim($datetimesql), -5, 2);
if($hours != '12')
$datetimesql = date('Y-m-d H:i',strtotime('+12 hour',strtotime($datetimesql)));
}
elseif ($ampm == 'am') {
$hours = substr(trim($datetimesql), -5, 2);
if($hours == '12')
$datetimesql = date('Y-m-d H:i',strtotime('-12 hour',strtotime($datetimesql)));
}
return $datetimesql;
}
Converte valori datetime come,
2015-06-04 09:55 AM -> 2015-06-04 09:55
2015-06-04 03:55 PM -> 2015-06-04 15:55
2015-06-04 12:30 AM -> 2015-06-04 00:55
Spero che questo vi aiuterà qualcuno.
fonte
2015-06-04 02:55:12
strtotime() http://php.net/manual/en/function.strtotime.php –
Dubito se è ciò che vuoi Voglio che tu noti che "m" in "H: m: s" rappresenta il mese in cifre. Credo che tu volessi scrivere "H: i: s". Si prega di crosscontrare – Paullo