Expand my Community achievements bar.

SOLVED

How to find the assets created since last run

Avatar

Level 5

My requirement is that my scheduled service will run at every 60 mins. I have done that.

Now I want to be able to find the assets created in last 60 minutes, I was writing a query for the same.So i created 

        DateTime dt = new DateTime();
        DateTime modified_last_run_date = dt.minusMinutes(60);
        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")

        String last_run_time =modified_last_run_date.toString(dtf);

    if I print the last_run_time string to console I get  --  "2015-08-19T17:38:36.221+0530"

However when I write Query :  SELECT p.* FROM [dam:Asset] AS p WHERE p.[jcr:created] >= CAST('2015-08-19T17:38:36.221+0530' AS DATE)  I get java.lang.IllegalArgumentException: Not a date string: 2015-08-19T17:38:36.221+0530

but if I write SELECT p.* FROM [dam:Asset] AS p WHERE p.[jcr:created] >= CAST('2015-08-19T17:38:36.221Z' AS DATE) I get no compilation error and query runs but with a lag of 5:30 hrs i mean i don't get correct results.

Can anybody suggest me solution.

In brief I want to find in each hourly run of my service which were the assets created since last run.

1 Accepted Solution

Avatar

Correct answer by
Level 10

as @siva mentioned, you need ':' to add in your time and your query should fetch you a result. You quickly try your query in 'tools -> query' in crxde

[img]Capture.JPG[/img]

View solution in original post

5 Replies

Avatar

Community Advisor

Did you try this SELECT p.* FROM [dam:Asset] AS p WHERE p.[jcr:created] >= CAST('2015-08-19T17:38:36.221+05:30' AS DATE)

Avatar

Level 10

Try using the QueryBuilder API to perform this task - look at this older community thread - Justin give some advice 

https://forums.adobe.com/thread/1261774

Avatar

Correct answer by
Level 10

as @siva mentioned, you need ':' to add in your time and your query should fetch you a result. You quickly try your query in 'tools -> query' in crxde

[img]Capture.JPG[/img]

Avatar

Employee Advisor

To fix this, update your pattern string to "yyyy-MM-dd'T'HH:mm:ss.SSSXXX". 

Avatar

Level 10

and to get ':' use this format yyyy-MM-dd'T'HH:mm:ss.SSSZZ