Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将每个dd-mm-yy转换为unix时间,并在“生日”字段中插入_Php_Date_Unix Timestamp - Fatal编程技术网

Php 将每个dd-mm-yy转换为unix时间,并在“生日”字段中插入

Php 将每个dd-mm-yy转换为unix时间,并在“生日”字段中插入,php,date,unix-timestamp,Php,Date,Unix Timestamp,请我想做一个很好的php函数,将我的html输入值转换成unixTime戳,然后插入我的mysql表字段 这是我的HTML代码 <input type="text" name="birthday_dd"/> <input type="text" name="birthday_mm"/> <input type="text" name="birthday_yy"/> 我的表单中有很多这样的html字段,每个字段都有一个带有&&&&&&&&&&&&&&&&&

请我想做一个很好的php函数,将我的html输入值转换成unixTime戳,然后插入我的mysql表字段

这是我的HTML代码

<input type="text" name="birthday_dd"/>
<input type="text" name="birthday_mm"/>
<input type="text" name="birthday_yy"/>


我的表单中有很多这样的html字段,每个字段都有一个带有&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


顺便说一句,您应该利用MySQL的
DATE
DATETIME
字段类型,而不是存储unix时间戳。

如前所述使用mktime,或者在发出INSERT查询时使用unix时间戳('YYYY-MM-DD')作为时间戳

看来你就要过生日了。UNIX时间戳在这里可能不是合适的工具,因为在UNIX时代之前出生的人会变得很棘手。我建议您改用适当的数据库类型。对于MySQL,您可以找到文档。

使用方法

$timestamp = mktime(0, 0, 0, $month, $day, $year)
e.g. $unix = strtotime("2014-11-10");