AEM Asset Metadata: Is there a way to store Node Data Type as "Date" for Simple Date Format Date? | Community
Skip to main content
BinaryAlchemy11
Level 3
March 13, 2023
Solved

AEM Asset Metadata: Is there a way to store Node Data Type as "Date" for Simple Date Format Date?

  • March 13, 2023
  • 1 reply
  • 1205 views

Hi AEM Community,

 

I have done some findings that AEM only accepts long date format (YYYY-MM-DDT00:00:00.000-05:00) as "Date" Data Type for the node. Is there any configuration that can be done to store Simple Date Format (“YYYY/MM/DD”) as "Date" Data Type?

Is there an alternative other than storing the node field as String to store the Simple Date Format? The reason is I am using this Date for the Query Builder API and using it as String won't allow me to query as "daterange" or "relativedaterange" to do the query operations. Any suggestions and best practice to address this issue would really be appreciated.

 

Best Regards,

Anish

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jagadeesh_Prakash

@binaryalchemy11  as a OOTB it is not possible but lets customize in sling model. Apart from that i dont see any option which i can think off. But it all dependends on the exact user case

1 reply

Jagadeesh_Prakash
Community Advisor
Community Advisor
March 13, 2023

@binaryalchemy11  By default, AEM does not provide an option to store a date in the format of "YYYY/MM/DD" as a "Date" data type. However, you can achieve this by writting a custom code to change the format

 

private Date date;

 

@ValueMapValue(name = "date")
private String dateString;

 

 

 

 

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
date = sdf.parse(dateString);
} catch (ParseException e) {
// handle the parse exception
}

BinaryAlchemy11
Level 3
March 13, 2023

Hi,

 

This would not work for my case as this would only be applicable if Date stored as String needs to be used for the logic.

 

The issue is as stated above, if I store the field as String data type then I will not be able to do the query builder operation of "daterange" for greater than or less than to filter out the assets.

 

0_group.1_group.daterange.property=jcr:lastModified
0_group.1_group.daterange.lowerBound=2015-04-18
0_group.1_group.daterange.lowerOperation=>=

Jagadeesh_Prakash
Community Advisor
Jagadeesh_PrakashCommunity AdvisorAccepted solution
Community Advisor
March 13, 2023

@binaryalchemy11  as a OOTB it is not possible but lets customize in sling model. Apart from that i dont see any option which i can think off. But it all dependends on the exact user case