Need to trim string formt value to yyyy-MM-dd format | Community
Skip to main content
Level 2
January 14, 2020

Need to trim string formt value to yyyy-MM-dd format

  • January 14, 2020
  • 1 reply
  • 2071 views

Hi,

Iam using custom report in my tool.And I need help for modify or append the condition for below  query. 

In metadata property name (lastLoginDate) is string format like 2019-06-21T14:36:59.734Z.But in report result column i need to show only on yyyy-MM-dd format (2019-06-21). Kindly help to trim the value and iam not filter the value.

This is my Query:

SELECT * FROM [dam:Asset] AS s where ISDESCENDANTNODE([{{path}}])
{{#if assetType}} AND [jcr:content/metadata/assetType]="{{{assetType}}}" {{/if}}
{{#if assetCreatedDate}} AND [jcr:content/metadata/assetCreatedDate]="{{country}}" {{/if}}
ORDER BY [jcr:content/metadata/assetCreatedDate] ASC

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

1 reply

arunpatidar
Community Advisor
Community Advisor
January 14, 2020

Hi,

Did you mean to convert from backend? or front end?

 

For Java you can use below:

 

 

/** * @90521 Calendar cal * @90521 String format * @2007960 string Formatted date in specified format e.g. Jan 01 2019 */ public static String getFormattedDate(Calendar cal, String format) { String date = ""; if (cal != null && StringUtils.isNotBlank(format)) { SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ENGLISH); date = formatter.format(cal.getTime()); } return date; }

 

 

or

 

/** * Converts AEM Date format "2011-11-10T10:20:59.400+01:00" to submitted format. * * @90521 String dateStr * @90521 String format * @2007960 string Formatted date ex: MMM DD YYYY format to Jan 01 2019 */ public static String getFormattedDate(String dateStr, String format) { if (StringUtils.isNotBlank(dateStr) && StringUtils.isNotBlank(format)) { try { SimpleDateFormat sdf = new SimpleDateFormat("MMM dd YYYY"); Date date = sdf.parse(dateStr); SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ENGLISH); return formatter.format(date); } catch (ParseException | StringIndexOutOfBoundsException e) { log.error("Not able to convert date, error : {}", e); } } return ""; }

 

Arun Patidar
Level 2
January 17, 2020

Hi arun,

I am expected query level change only.need to add the condition in query section.