获取在特定日期之前添加的任何行
这可能吗?我用它来将日期插入到名为“date”的字段中:
$date=date("m/d/y");
$sql="INSERT INTO pool (date) VALUES('$date' )";
$result=mysql_query($sql);
我用这个语句来获取一周前的日期:
$variable = date('d-m-y', strtotime('-1 week'));
那么我将如何选择上周添加的任何行?
Would this be possible? I've used this to insert the date into a field called "date":
$date=date("m/d/y");
$sql="INSERT INTO pool (date) VALUES('$date' )";
$result=mysql_query($sql);
I've used this statement to get the date a week ago:
$variable = date('d-m-y', strtotime('-1 week'));
So how would I SELECT any rows which were added last week?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应将日期存储为
m/d/y
,而应将其存储为 Ymd :在数据库中,您的日期将类似于
2011-04-09
。这种格式更容易使用:按字母顺序比较会起作用。
这意味着搜索早于某个日期的行将变成如下所示:
另请注意,您可以使用
DATE
列 - 这将允许与 MySQL 中的日期和时间函数。Instead of storing your dates as
m/d/y
, you should store them as Y-m-d :In the database, you dates will then look like
2011-04-09
.That format is much easier to work with : alphabetical comparisons will work.
Which means that searching for rows that are older than a certain date would become something like this :
Also note that instead of working with a
date
field which is a varchar (or an equivalent) in your database, you could use aDATE
column -- which would allow to to work with date and time functions in MySQL.如果日期字段是正确的日期类型,您可以执行 <或>在你的sql查询中。例如 -
如果您想要 1 周前到现在的所有内容,您可以执行上述操作或
If the date field is a proper date type you can do < or > in your sql query. For example -
If you want everything from 1 week ago to now you can do something like the above or