简体   繁体   English

大于或等于日期

[英]Greater than or equal to a date

I have a table that has a field called date1. 我有一个表,其中有一个名为date1的字段。

When I look at the table in Access GUI datasheet view, I can see the dates are "correct in that date1 runs from October 1st 2013 to today, June 19th 2014. When I look at table1 in design view I can see that date1 is formatted as m/d/yyyy. 当我查看Access GUI数据表视图中的表时,我看到的日期是“正确的,因为date1从2013年10月1日到今天(2014年6月19日)运行。当我在设计视图中查看table1时,我看到date1已格式化作为m / d / yyyy。

So when I ran this query I expected to see results only for April 1st 2014 till today. 因此,当我运行此查询时,我希望只能看到2014年4月1日至今的结果。 But instead I see results going back to 2013. 但是我看到的结果可以追溯到2013年。

SELECT *
FROM someTable
WHERE ((([someTable].medium1)='Direct'))
OR ((([someTable].medium1)='Paid Search') 
AND (([someTable].date1)>=#4/1/2014#));

I tried removing the # too. 我也尝试删除#。 I only added those after doing some Google searching. 我只是在进行一些Google搜索后才添加的。

Can anyone spot why my query is returning results where date1 is less than April 1st 2014? 谁能发现为什么我的查询返回的date1小于2014年4月1日的结果?

I think your OR is throwing off results. 我认为您的手术结果不理想。

Is the date inclusive of the other criteria? 该日期是否包含其他条件? (meaning all values should be after that date? if so the where clause is off. (表示所有值都应在该日期之后?如果是,则where子句关闭。

SELECT *
FROM someTable
WHERE ([someTable].medium1 = 'Direct' OR [someTable].medium1 = 'Paid Search')
AND   ([someTable].date1)>=#4/1/2014#);

Or... 要么...

SELECT *
FROM someTable
WHERE [someTable].medium1 in ('Direct', 'Paid Search')  
 AND  [someTable].date1 >= #4/1/2014#;

or... 要么...

SELECT *
FROM someTable
WHERE ([someTable].medium1='Direct' OR [someTable].medium1='Paid Search')
AND   [someTable].date1>=#4/1/2014#;

The data in the view depends of the field format. 视图中的数据取决于字段格式。 When the query is launched, the data is returned "as-is. You have to ensure the date format by using the format function. 启动查询时,将按原样返回数据。您必须通过使用format函数来确保日期格式。

Use this query instead: 使用以下查询:

select *
from someTable
where someTable.date1 between format("04/01/2014","mm/dd/yyyy") and now()
and someTable.medium1 in ('Direct','Paid Search')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM