Gravatar for arulselvan.arivazhagan@cfainstitute.org

Question by Arulselvan, Dec 7, 2017 8:40 PM

Modify Date format in result view

Requirement is to change date format in the result. Below hightlighted date format needs to be changed to "13 November 2017". kindly suggest on this. Thanks in advance.si

2 Replies
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Dec 7, 2017 10:38 PM

Depending on the version of JS UI you are using, you can either use:

`Globalize.format(Coveo.DateUtils.convertToStandardDate(1512680420000), 'd MMMM yyyy')`

Or:

`Globalize.format(Coveo.DateUtils.convertFromJsonDateIfNeeded(raw.sysdate), 'd MMMM yyyy')`

See https://coveo.github.io/search-ui/classes/dateutils.html#converttostandarddate for more information

Gravatar for arulselvan.arivazhagan@cfainstitute.org

Comment by Arulselvan, Dec 7, 2017 11:30 PM

I have tried the above code,

Case1:

<a>{{-Coveo.DateUtils.convertFromJsonDateIfNeeded(raw.sysdate)}}</a>

Output:

Wed Nov 15 2017 13:13:05 GMT-0500 (Eastern Standard Time)

Case2:

<a>{{-Globalize.format(-Coveo.DateUtils.convertFromJsonDateIfNeeded(raw.sysdate), 'd MMMM yyyy')}}</a>

Output:

-1510769585000

Am i missing anything here?

Thanks in advance.

Gravatar for arulselvan.arivazhagan@cfainstitute.org

Comment by Arulselvan, Dec 7, 2017 11:52 PM

= Globalize.format(Coveo.DateUtils.convertFromJsonDateIfNeeded(raw.sysdate), 'd MMM yyyy')

I missed "=". Thank a lot for your help.

Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Dec 8, 2017 3:12 PM

In the result templates , there are many Helpers, like the `date()` method which accepts a `Date` object and you can see the second option, which is a DateToStringOptions.

The `predefinedFormat` attribute is what you need:

dateTime(raw.sysdate, { predefinedFormat: "yyyy-MM-D" })

outputs:

2017-09-27

Ask a question