[英]How to select a php date() format in SQL
I have an SQL table with a field "time_created"
in the form "Wed, 19 Aug 2015 03:58:00 -0600"
. 我有一个SQL表,字段为
"time_created"
,格式为"Wed, 19 Aug 2015 03:58:00 -0600"
。 I need to check this field against today and perform a where statement according to it, as in 我需要对照今天检查此字段并根据它执行where语句,如
SELECT * FROM table WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(time_created) >= 3600*24*30
to select records where time_created
is older then a month. 选择
time_created
一个月大的记录。
Problem is UNIX_TIMESTAMP
doesn't understand formats as "Wed, 19 Aug 2015 03:58:00 -0600"
. 问题是
UNIX_TIMESTAMP
无法将格式理解为"Wed, 19 Aug 2015 03:58:00 -0600"
。 Any other way? 还有其他方法吗?
Try: 尝试:
SELECT *
FROM table
WHERE DATE(NOW()) > DATE_SUB(STR_TO_DATE(time_created, '%a, %e %b %Y %T'), INTERVAL 1 MONTH)
This will find all records where the current date ( DATE(NOW())
) is bigger than time_created
subtract ` month. 这将查找当前日期(
DATE(NOW())
)大于time_created
减去`month的所有记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.