在插入数据库之前,将用户输入的日期和时间转换为Unix时间戳 [英] Convert User entered date and time to Unix Timestamp before inserting to database

查看:89
本文介绍了在插入数据库之前,将用户输入的日期和时间转换为Unix时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将用户输入的日期转换为unix时间戳

将其导入数据库?我有一个表格,带有一个用于

a日期的文本字段,用户输入的格式为mm-dd-yyyy和三个dropdow

框,包括小时,分钟和AM /下午。所有这些都需要一起考虑

并转换为一个Unix时间戳,然后插入到

MYSQL日期字段中。字段的类型是INT(11),因此我可以改为使用MYSQL的标准0000-00-00格式的
,这样我就可以做得更好

计算和查询。怎么能实现呢?


谢谢。

How do you convert a user inputted date to a unix timestamp before
insterting it into your database? I have a form, with a textfield for
a date that the user inputs in the format mm-dd-yyyy and three dropdow
boxes for hours, minutes, and AM/PM. All of these need to be considered
together and converted to one Unix Timestamp and then inserted to the
MYSQL date field. The type of field is INT (11) so that I can instead
of the standard 0000-00-00 format of MYSQL so that I can do better
calculations and queries. How can this be accomplished?

Thanks.

推荐答案

这里有一些代码来说明我的问题。我将下拉菜单改为输入框,以便缩短发布时间,但概念是

相同......


<?php require_once(''Connections / con_date.php''); ?>

<?php

mysql_select_db(
Here''s some code to illustrate my question. I changed the dropdown
boxes to input boxes to make it shorter to post, but the concept is the
same...

<?php require_once(''Connections/con_date.php''); ?>
<?php
mysql_select_db(


database_con_date,
database_con_date,


con_date );
con_date);


这篇关于在插入数据库之前,将用户输入的日期和时间转换为Unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆