Format date with "2 days, 5 hours" format in JSP tags

Hi,

I want to format a date that I am using in a JSP tag so it shows “x days x hours” as shown in the properties page of a date in a section.

Is this possible at all just using the simple format tag (as used below but obviously not dd/MM/yyyy :slight_smile: )

<pega:reference name=".SomeDate" format="dd/MM/yyyy"/>

Or is it going to be a lot more complex?

TIA

Darren

Hi @DarrenP9841,

Hope you are doing well.

Yes, it is possible to format a date in Pega to show “x days x hours” using the simple format tag. Here’s how you can do it:
<fmt:formatDate value=“${yourDate}” type=“relative”/>

The fmt:formatDate tag is a JSP tag that allows you to format dates. The type attribute specifies the format of the date. In this case, we are using the relative type, which formats the date as a relative time, such as “x days x hours”.

For example, if your yourDate variable contains the date 2023-03-08 10:30:00, the above code will output something like “3 days 12 hours”.

Note that the relative type is only available in Pega 8.5 and later. If you are using an earlier version of Pega, you will need to use a different formatting method.

I hope it helps.

Thanks

Megha

Hi @DarrenP9841 ,

You can use formatAsDuration for the requirement.

Thanks

@Megha007 , Thanks for the promt reply. Just checking, am I right in thinking to use fmt I will need to add the library ?