Alex Rivera | Logout

What's the recommended way to store current time using PHP and MySQL?

Asked 2010-02-24T05:44:08.733
11

My initial approach was:

$current = time(); // save this to column CURRENT_TIME with column type VARCHAR

//retrieve it like this
$retrieved = mysql_query(....) //assume query for getting the stored time value
$time = strtotime($retrieved);

I have come across the following approaches:

  1. use gmstrftime to handle gmt
  2. use INT instead of VARCHAR for the column
  3. use the mysql function CURTIME or CURDATE
  4. use the UNIX_TIMESTAMP mysql function

none of which were using the DATETIME or TIMESTAMP mysql var type.

Do you have a better approach for this one?

Edit
Report

1 Answer

0

Storing it as int is more logical. You save the row format of date, using which you can later extract other format and more data .. I also save it as int.

Edit: For(Uni-TimeZone) application int is the fastest way and PHP has great time conversion tools.

answered 2010-02-24T06:24:35.850

Your Answer