php - Why does MySql format datetime microseconds as .000000? -
i not sure why, when new record added database table, format of time followed period , 6 zeros. example
2014-03-24 11:00:03.000000
i using following php code date , time
date("y-m-d h:i:s")
the record added database via array, passed through following function:
$record = array( 'date' => date("y-m-d h:i:s") );
function:
$data = '`' . implode('`, `', array_keys($record)) . '`'; $values = '\'' . implode('\', \'', $record) . '\''; mysql_query(" insert `". $table ."` ($data) values (". $values .") ");
i don't think mysql supports microseconds, ideally remove makes table messy. suggestion on how can remove microseconds?
if care format of datetime
value when returned, use date_format()
:
select date_format(col, '%y-%m-%d %h:%i;%s') yyyymmss_hhmmss
don't depend on database returning value in particular format, if want in format.
as question of "why" mysql this. because can. database free return date , datetime values likes. creators of mysql chose general format column contain fractional seconds. key point shouldn't depend on this, if want particular format. mysql has excellent functional support formatting dates , reading dates strings.
Comments
Post a Comment