我最初的做法是:
$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);
Run Code Online (Sandbox Code Playgroud)
我遇到过以下方法:
gmstrftime处理GMTINT而不是VARCHAR列CURTIME或CURDATEUNIX_TIMESTAMPmysql函数没有一个使用DATETIME或TIMESTAMPmysql var类型.
你对这个有更好的方法吗?
Ale*_*xar 19
建议使用mysql 时间戳(YYYY-MM-DD HH:MM:SS)字段类型在mysql中存储时间和日期变量.
$sDate = date("Y-m-d H:i:s"); // 2015-04-07 07:12:51
mysql_query("insert into `table_name` set `created_on` = '$sDate'");
Run Code Online (Sandbox Code Playgroud)
它使您能够使用mysql函数来比较日期,计算时间差等,直接在您的mysql查询中.
您也可以使用strtotime()函数检索时间戳.
$result = mysql_query("select `created_on` from `table_name`");
$row = mysql_fetch_row($result);
$iTimestamp = strtotime($row[0]); // 1428390771
Run Code Online (Sandbox Code Playgroud)