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

mohanasundaramp 14-01-2020

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

Mark Solution

Are these answers useful?
Help other community members by marking useful answers as accepted.

Accepted Solutions (0)

Answers (1)

Answers (1)

Arun_Patidar
MVP
14-01-2020

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 "";
    }