我最初的做法是:
$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);我遇到了以下几种方法:
gmstrftime处理格林尼治时间INT而不是VARCHARCURTIME或CURDATEUNIX_TIMESTAMP mysql函数其中没有一个使用DATETIME或TIMESTAMP mysql类型。
你有更好的方法吗?
发布于 2010-02-24 06:29:36
建议使用mysql 时间戳(YYYY: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'");它使您能够使用mysql函数直接在mysql查询中比较日期、计算时间差等等。
此外,您还可以使用标准时间()函数检索时间戳。
$result = mysql_query("select `created_on` from `table_name`");
$row = mysql_fetch_row($result);
$iTimestamp = strtotime($row[0]); // 1428390771发布于 2010-02-24 09:06:44
我只在MySQL中使用MySQL值类型,让MySQL使用自己的CURRENT_TIMESTAMP。
发布于 2010-02-24 05:46:33
好的,您可以使用MySQL将strtotime()时间戳字段转换为PHP ()值
然后,您只需创建一个将PHP ()值正确转换为MySQL时间戳值的函数。
https://stackoverflow.com/questions/2323945
复制相似问题