0

I am using the SharePoint search Results web part which uses Handlebars JS.

I have two dates in these variables:

{getDate EventDateOWSDATE}
{getDate EndDateOWSDATE}}

I need to check if the 2 dates are on the same day, and if they aren't, I need to display to the browser 1day, 2day etc.

So if:

EventDateOWSDATE = 27/02/2021

EndDateOWSDATE = 29/02/2021

Print to the browser: 3 days

I could do this using JavaScript and moment, but not sure how to do this inside this web part using handlebars and I don't think I can add libraries like moment.

1 Answer 1

1

You can create a custom handlebar helper like I mentioned in your previous post.

Example:

public registerHandlebarsCustomizations(namespace: typeof Handlebars) {
    namespace.registerHelper('compareDates', function(startDate, endDate) {
        //Your logic goes here
        //return expected result
    });
}

Below links will help you to get started with custom logic:

  1. Using handlebars helpers to detect if two dates match
  2. Handlebars Expressions
1
  • 1
    <3 Thank you Ganesh!
    – BennKingy
    Feb 27, 2021 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.