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
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Validate 1
Level 1
mohanasundaramp
Level 1

Like

1 like

Total Posts

30 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back
Boost 1
View profile

Avatar
Validate 1
Level 1
mohanasundaramp
Level 1

Like

1 like

Total Posts

30 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back
Boost 1
View profile
mohanasundaramp
Level 1

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

Replies

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
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 "";
    }

 

Avatar

Avatar
Validate 1
Level 1
mohanasundaramp
Level 1

Like

1 like

Total Posts

30 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back
Boost 1
View profile

Avatar
Validate 1
Level 1
mohanasundaramp
Level 1

Like

1 like

Total Posts

30 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back
Boost 1
View profile
mohanasundaramp
Level 1

16-01-2020

Hi arun,

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

 

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

17-01-2020

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