问题
please i want to make a nice php function that convert my html input values into a unixTime stamp and than insert to my mysql table field
This is my HTML code
<input type="text" name="birthday_dd"/>
<input type="text" name="birthday_mm"/>
<input type="text" name="birthday_yy"/>
i have a lots of this html fields in my form each one termin with _dd & _mm & _yy so i want to merge this 3 html input values and convert them into a unix timeStamp before insert into my Mysql Table field
回答1:
To get a UNIX timestamp from the date parts, you can use mktime()
$timestamp = mktime(0, 0, 0, $month, $day, $year)
By the way, you should take advantage of the DATE
and DATETIME
field types of MySQL instead of storing unix timestamps.
回答2:
Use mktime as stated previously or make them a timestamp with UNIX_TIMESTAMP('YYYY-MM-DD') when you issue your INSERT query !
回答3:
It seems you are about to handle birthday. UNIX timestamps might not be the right tool here, because it gets tricky when someone is born before the UNIX era. I would recommend you, to use the appropriate database types instead. In case of MySQL you'll find the documentation here.
回答4:
Use strtotime method,
e.g. $unix = strtotime("2014-11-10");
来源:https://stackoverflow.com/questions/22505786/convert-each-dd-mm-yy-to-unix-time-and-insert-in-birthday-date-field