1

我有基于日期的过滤条件。它需要在给定日期之间获取记录。在我给出的表达式过滤中,字段是日期日期类型,格式是YYYYMMDD

fieldname >= '20020502' and fieldname <= '20050430'

但记录不通过下一个组件。

我给的条件正确吗?

4

4 回答 4

0

我有另一种总是有效的方法....

使用 date_diff 函数同样......

条件将提供如下:

Date_diff(date1,fieldname).days >0 & & date_diff(date2,fieldname).days<0
于 2015-12-28T16:40:03.520 回答
0

正如你所提到的

字段已经是 YYYYMMDD 格式的日期数据类型

您只需对表达式的右侧进行类型转换。

 my_date >= (date("YYYYMMDD")) "20150102" && my_date <= (date("YYYYMMDD")) "20150105"

考虑的输入数据和输出是:

20150101

20150102  --> with the above condition goes to output

20150103  --> with the above condition goes to output

20150104  --> with the above condition goes to output

20150105  --> with the above condition goes to output

20150106
于 2016-03-21T20:53:04.407 回答
0

您需要在这里检查的第一点是该字段的数据类型是什么。

如果字段是日期或日期时间类型,则直接使用 date_diff() 等函数。

如果该字段是字符串或十进制类型,则在使用 date_diff() 等函数之前,需要对日期或日期时间进行类型转换。

谢谢

阿里吉特

于 2016-03-16T11:44:55.560 回答
0

尝试对日期进行类型转换。

(date("YYYYMMDD"))fieldname => '20020502' and (date("YYYYMMDD"))fieldname <= '20050430'
于 2016-01-25T09:26:51.067 回答