I want to format a Date (StartDate and EndDate) in Moment React. Unfortunately, it's always giving me an error message.

Maybe you can help me!

Here is my code so far:

this.state.ProjectFilterItem.forEach((item:IListItem)=> project.push(

  <div className={styles.containerGrid}>
    <div className={styles.ProjectTitleHeader}>item 1 {item.Title}</div>
      <div className={styles.imageTL}>
      <img src={item.TrafficLight?.Title == "Green" ? 'https://url/sites/PMO-PoC/Shared%20Documents/TrafficLight/TrafficLight-green.png':
                item.TrafficLight?.Title == "Yellow" ? 'https://url/sites/PMO-PoC/Shared%20Documents/TrafficLight/TrafficLight-yellow.png':
                 item.TrafficLight?.Title == "Red" ? 'https://url.sharepoint.com/sites/PMO-PoC/Shared%20Documents/TrafficLight/TrafficLight-red.png': ''}></img>
    <div className={styles.ProjectStartdate}>item 3 {moment({item.StartDate}).format('DD.MM.YYYY')}</div>
    <div className={styles.ProjectEnddate}> item 4 {item.EndDate}</div>
    <div className={styles.ProjectStatus}>item 5 {item.ProjectStatus?.Title}</div>
    <div className={styles.ProjectPhase}>item 6 {item.ProjectPhase?.Title}</div>
  • What is the error message? Can you try this: moment(new Date(item.StartDate)).format('DD.MM.YYYY'). Let me know if it works for you. Commented Sep 27, 2022 at 13:58
  • did you try above suggestion? is it working for you? Commented Aug 3, 2023 at 11:53

1 Answer 1


Instead of this:

<div className={styles.ProjectStartdate}>item 3 {moment({item.StartDate}).format('DD.MM.YYYY')}</div>

Use this:

<div className={styles.ProjectStartdate}>item 3 {moment(new Date(item.StartDate)).format('DD.MM.YYYY')}</div>

Documentation: Moment JS Docs

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.