2

I'm getting a Date from GraphQl query. When I get the result, it is coming as 20200415T123050Z.

If I try to format using

<DateField field={item.publishDate} render={(date) => date.toLocaleDateString()} />

(tried it with dateOptions as well ) it says "Invalid Date" on the page.

Is there a way to format the date in GraphQL or after I have received the searchResult?

Thanks

1 Answer 1

1

Try retrieve jss of date field in graphQL instead of value and render the same using .

Sample graphQL call

query RetDates($itemPath: String = "/sitecore/Content/TestItems") {
  folderItem: item(path: $itemPath)
  {
    children{
      dateVal: field(name:"dateVal")
      {
        jss
      }
    }
  }
}

Sample rendering

<DateField field={child.dateVal.jss} render={(date) => date.toLocaleDateString()} />

The above change will render date like this,

enter image description here

1
  • Thanks @Gobinath Saminathan. it worked.
    – Kanchan
    Commented May 26, 2020 at 13:03

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.