php - Database time format change -


for database time, have following:

date_default_timezone_set('canada/mountain'); $comment_date = date('m/d/y h:i:s a', time());   $data = array(                                  'comment_date' => $comment_date              ); 

but getting 0000-00-00 00:00:00 results.

i trying show time in "1 min" or "20 hr" or "4 days" format.

how achieve this?

it looks may using mysql. assuming this, change

$comment_date = date('m/d/y h:i:s a', time());

to

$comment_date = date('y-m-d h:i:s');

and should retain correct date when save database. reason mysql expects datetime in latter format.

i'm not sure mean i trying show time in "1 min" or "20 hr" or "4 days" format. can use mysql date_format() function format date when extract database. see http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format details on how this.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -