Here's the scenario. User enters 3 types of inputs:
1/1/2013 12:00:00 AM_5/31/2013 12:00:00 AM
1/1/2013 12:00:00 AM_
_5/31/2013 12:00:00 AM
The input is for date range query.
1st input: Split by the _ delimiter: Broken into Start date and end date.
2nd input: Split by the _ delimiter: Input is only the start date.
3rd input: Split by the _ delimiter: Input is only the end date.
Input is retrieved by generic return type.
if (StringUtils.endsWithIgnoreCase(searchKey, "date")) {
String dates[] = searchValue.split("_",-1);
if (dates [0] == null)
{
long epoch = System.currentTimeMillis()/1000;
String format = "MM/dd/yyyy HH:mm:ss aaa";
dates[0] = new
java.text.SimpleDateFormat(format).format(new java.util.Date (epoch*1000));
}
else if (dates [1] == null)
{
Date dNow = new Date( );
dates[1] = DateFormat.getInstance().format(dNow);
}
String start = dates[0];
String end = dates[1];
String format = AppConstant.DATE_FORMAT;
filters.add(String.format("%s between to_date('%s', '%s') and to_date('%s', '%s')", columnKey, start, format, end, format));
}
As you can see the whole idea is:
- if there is no start date is entered by the user, the epoch date will be used as the start date.
- if there is no last date is entered by the user,the current date n time will be used as the end date.
But unfortunately,this coding does not work. I'm guessing the problem is Split doesn't store a NULL value hence the if statement is not working.
I'm still relatively new to java and any help is very much appreciated.