issue with date conversion
I'm trying to get the last 30 days of data for an imported csv, but the system tells me that my dateformats are incompatible. However, i can's see any real reason why or workaround, so any advice is welcome.
My process is as follows :
-> read csv, date is imported as nominal and is formatted as 'YYYY-MM-DD HH:mm:ss'
-> Nominal to date, date type = date_time, this gives me my date (entryTime) in following format on screen: Jan 7, 2017, 4:15:33 AM CET, but when I copy it it looks like this : Sat Jan 07 16:15:33 CET 2017
-> Next I create a macro called startdate, using following function : date_add(date_now(),-30,DATE_UNIT_DAY), which results in something like Jun 30, 2017 7:13:46 PM CEST
-> next I create a filter stating that my datefield needs to be bigger or equal than %{startdate} but it gives me an error stating :
'cannot instantiate custom filters: the filter value 'Jun 30, 7:20:30 PM CEST for the attribute entryTime is not in a valid format. Formatting example: 12/31/2014 3:00:00 PM.
So I assume I need to change my dateformat somehow, but if I use date to nominal in the MM/dd/yyyy format and then back nominal to date I get the same problem. So what do I need to do, or are there other ways to filter dateranges?
Answers
Hi,
check the SimpleDateFormat documentation:
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
The DD is the number of days in the year, not the month.
HH is the actual number of hours (0-23), you should use that if you don't have AM/PM indicators.
Regards,
Balázs
Hi,
The following XML codes provides 2 other possible solutions.
Both make use of Generate Attribute to generate a helper Attribute which is further used for filtering your dataset.
As a general remark: When working with dates I tend to use the conversion to milliseconds most of the time, since they are easier to follow.
The first example goes step-by-step converting to millliseconds, generating the filter macro & filter the relevant examples.
The second example checks if the date fulfills a certain condition (here:
and returns a specified value which saves one Operator.
Best,
Edin