0

I am facing an issue in react js. I want to match alltime with my start_time but it is not matching with start_time. What is the mistake?

rest api

"appointments": [
{
"id": "23",
"start_date": "2020-05-13 16:00:00",
"end_date": "2020-05-13 16:30:00",
"cust_full_name": "CodupCustomer",
"full_name": "Test staff 2",

all time data:
[Wed May 13 2020 19:00:00 GMT+0500 (Pakistan Standard Time), 
Wed May 13 2020 19:30:00 GMT+0500 (Pakistan Standard Time), 
Wed May 13 2020 20:00:00 GMT+0500 (Pakistan Standard Time)]

fetch data

  componentDidMount() {
    axios.get(`http://localhost/v1/appointments`)
    .then(res => {
      const appointmentdata = res.data; 
        this.setState({ 
          appointmentdata :appointmentdata.appointments 
        });
      })
    }

My component


    <div class="row">
          {this.state.appointmentdata && this.state.appointmentdata.length
        ?   this.state.appointmentdata


    var alltime = [prevDate,nextDate,firstDate,secDate,thirDate];

    for(var i=0;i<alltime.length; i++){
      const date = new Date(start_date);

      if(date.toString() == alltime[i].toString()){
        return ( 
          <div class="w-name">
            {full_name}
            <p>{cust_full_name}</p>
          </div>
        )
      }
              else {
              // console.log("cust",cust_full_name);
              return( <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 col-3 without-name">
              <p>hassan</p>
              </div> ) 
              }

              }

            }
          )
        : null}

console.log

start Wed May 13 2020 16:00:00 GMT+0500 (Pakistan Standard Time)
alltime Wed May 13 2020 19:00:00 GMT+0500 (Pakistan Standard Time)
start Wed May 13 2020 15:30:00 GMT+0500 (Pakistan Standard Time)
alltime Wed May 13 2020 19:00:00 GMT+0500 (Pakistan Standard Time)
start Wed May 13 2020 19:00:00 GMT+0500 (Pakistan Standard Time)
alltime Wed May 13 2020 19:00:00 GMT+0500 (Pakistan Standard Time)
start Wed May 13 2020 14:30:00 GMT+0500 (Pakistan Standard Time)
alltime Wed May 13 2020 19:00:00 GMT+0500 (Pakistan Standard Time)

I want to match alltime with my start_time

MHasan
  • 69
  • 1
  • 8
  • 1
    Impossible to know when you have not posted examples of allTimes – mplungjan May 13 '20 at 14:28
  • What's `start_date`? Where does it come from? – GaloisGirl May 13 '20 at 14:30
  • ok i explain my question? [@](https://stackoverflow.com/users/295783/mplungjan) – MHasan May 13 '20 at 14:30
  • i updated the post [@](https://stackoverflow.com/users/735964/galoisgirl) – MHasan May 13 '20 at 14:40
  • i updated the post [@](https://stackoverflow.com/users/295783/mplungjan) – MHasan May 13 '20 at 14:44
  • hav you understand [@](https://stackoverflow.com/users/735964/galoisgirl) – MHasan May 13 '20 at 14:48
  • Here I have bit confused what is Start time? are you talking about the start date property in the appointments array. You have done the date comparison so nicely. Everything is good to go. **What exactly you are trying to explain.** I would suggest you to ```use strict equality === instead of ==``` and alltime array contains only string. So ```no need to use toString() for alltime[i]``` – Ram May 15 '20 at 11:27

0 Answers0