2013-08-29 139 views
1

如果在selectedStartDateFromselectedStartDateTo变量中未指定,我需要使用if语句来设置startDateFromstartDateTo中的日期。与if语句的日期比较

然后我想用startDateFromstartDateToExperiment_Instance_Start_DatestartDateFromstartDateTo之间的过滤条目。

日期比较工作正常,它只是当我添加if语句,它停止工作。任何想法我在这里做错了吗?

| eval compare=strptime(Experiment_Instance_Start_Date,"%m/%d/%Y") 
| where compare>=strptime(startDateFrom,"%m/%d/%Y") 
| eval compare=strptime(startDateTo,"%m/%d/%Y") 
| where compare>=strptime(Experiment_Instance_Start_Date,"%m/%d/%Y") 
| eval startDateFrom=if("$selectedStartDateFrom$"="", "01/01/1970", "$selectedStartDateFrom$") 
| eval startDateTo=if("$selectedStartDateTo$"="", "01/01/2100", "$selectedStartDateTo$") 

回答

0

原来"$selectedStartDateFrom$"=""是不对的,所以我改变了对len("$selectedStartDateFrom$")>0。我还需要将if语句移至startDateFromstartDateTo的日期比较之前。 01/01/1970的开始日期也没有返回结果,所以我将其更改为更晚的日期。

| eval startDateFrom=if(len("$selectedStartDateFrom$")>0, "$selectedStartDateFrom$", "01/01/2000") 
| eval startDateTo=if(len("$selectedStartDateTo$")>0, "$selectedStartDateTo$", "01/01/2099") 
| eval compare=strptime(Experiment_Instance_Start_Date,"%m/%d/%Y") 
| where compare>=strptime(startDateFrom,"%m/%d/%Y") 
| eval compare=strptime(startDateTo,"%m/%d/%Y") 
| where compare>=strptime(Experiment_Instance_Start_Date,"%m/%d/%Y")