Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

how to extract year from date with timestamp from jcr:property of a page using querybuilder api aem

Avatar

Level 2

I have two filters on page viz. Year & Category. Based on this filters i need to retrieve the pages from the repository and show it on the page. I am using querbuilder api to fetch the pages based on searching "year & category" properties in the page property of the list of pages.However, I have a date property in page properties of list of pages from where i need to compare the year filter of my query. But filter=year is in the format "2017" & date=timestamp in pageproperties of page is in format of "2017-09-18T01:15:00.000+05:30". So how do i compare the year filter & date in page properties to fetch these particular pages through my query.

query map: 
  if (StringUtils.isNotBlank(year)) {
  map.put("3_property", "year");
  map.put("3_property.value", 2017);
  }

page property:

Capture.PNG

1 Accepted Solution

Avatar

Correct answer by
Level 2

Got the solution.

map.put("daterange.property", "date"); //Since the property name is date as per your image.
map.put("daterange.lowerBound", year + "-01-01"); //First day of the year
map.put("daterange.upperBound", year + "-12-31"); //Last day of the year

View solution in original post

2 Replies

Avatar

Correct answer by
Level 2

Got the solution.

map.put("daterange.property", "date"); //Since the property name is date as per your image.
map.put("daterange.lowerBound", year + "-01-01"); //First day of the year
map.put("daterange.upperBound", year + "-12-31"); //Last day of the year