Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

mohanasundaramp
Level 3
Level 3

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

0 Replies
Arun_Patidar
Community Advisor
Community Advisor

Hi,

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

 

For Java you can use below:

 

 

/**
* @Param Calendar cal
* @Param String format
* @Return 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.
     * 
     * @Param String dateStr
     * @Param String format
     * @Return 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 "";
    }

 

mohanasundaramp
Level 3
Level 3

Hi arun,

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

 

Arun_Patidar
Community Advisor
Community Advisor

The Queries are read-only, you can read the values but can't manipulate the values while returning.