选择日期==现在+ 21天(不包括)的记录

问题描述:

我有一个表session_dates,其中包含一些字段和一个名为timestart时间戳字段.

I have a table session_dates with some fields and a timestamp field named timestart.

我想做的是从表中选择所有记录,其中字段 timestart (时间戳)等于从现在开始的21天.

What I would like to do is select all the records from my table where the field timestart (TIMESTAMP) is equal to 21 days from now.

例如,如果今天是1月27日-> 2月17日.

我知道如何选择两个日期之间的所有日期. 我在2个日期之间进行的SQL查询:

I know how I can select all between two dates. My SQL Query for between 2 dates:

SELECT timestart, timefinish, sessionid 
FROM sessions_dates 
WHERE timestart BETWEEN UNIX_TIMESTAMP(NOW()) AND UNIX_TIMESTAMP(DATE_ADD(NOW(), INTERVAL 21 DAY))

但是如何选择等于日期呢?

But how to select equal to a date?

更新:

我现在知道我只需要使用=语句.但是我该如何测试呢?我怎么知道UNIX_TIMESTAMP(DATE_ADD(NOW(), INTERVAL 21 DAY))返回什么?

I know now that I just have to use the = statement. But how can I test this? How do I know what the UNIX_TIMESTAMP(DATE_ADD(NOW(), INTERVAL 21 DAY)) returns?

我认为您想要:

SELECT timestart, timefinish, sessionid 
FROM sessions_dates 
WHERE timestart >= UNIX_TIMESTAMP(DATE_ADD(NOW(), INTERVAL 21 DAY)) AND
      tmestamp < UNIX_TIMESTAMP(DATE_ADD(NOW(), INTERVAL 22 DAY))

大概,timestart具有时间分量.此版本考虑了这一点,并且仍然允许在timestart上使用索引.

Presumably, timestart has a time component. This version takes that into account and still would allow the use of an index on timestart.