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>

Thanks in advance!


  • 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. Sep 27, 2022 at 13:58


Your Answer

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