我想要一个按钮,用户可以在其中输入日期格式,例如2010 年 12 月 22 日上午 07:55
。但如果它的格式只是 2010 年 12 月 22 日
,那就太好了
在尝试在 mysql 查询中处理它时,应将其转换为这种格式的时间 1292984705
。
mysql_query("SELECT * FROM order_history where date>'$time1' AND date<'$time2' ORDER By id DESC");
最佳答案
使用 strtotime()
将日期的字符串表示形式转换为 UNIX 时间戳的函数:
mysql_query("SELECT * FROM order_history where date > " . strtotime($time1) . " AND date < " . strtotime($time2) . " ORDER By id DESC");
请注意,我删除了连接时间戳周围的引号,这将对时间戳执行真正的算术运算。
关于php - 使用 PHP 在 SQL 查询中指定时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4506128/