Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Incorrect Date Value

bit stumped on a small problem, I'm trying to disable dates over the Christmas period. For some reason the last date in December is returning the incorrect month. Please see my code below:

disabledDates = [
    new Date(2018,3,2),
    new Date(2018,2,30),
    new Date(2018,4,28),
    new Date(2018,7,27),
  ];

  @php
  $arrival = strtotime('-1 day', strtotime(env('CHRISTMAS_ARRIVAL_DATE')));
  $return = strtotime('+1 day', strtotime(env('CHRISTMAS_RETURN_DATE')));
  @endphp

  christmasDates = [
  @while($arrival <= $return)
    @php
    $month = date('n', $arrival) == 1 ? 0 : date('n', strtotime('-1 month', $arrival));
    @endphp
    new Date({{ date('Y', $arrival) }},{{ $month }},{{ date('d', $arrival) }}),
    @php
    $arrival = strtotime('+1 day', $arrival);
    @endphp
  @endwhile
  ];

  $.merge(disabledDates, christmasDates);

The output from that is:

//Dates disabled...
  disabledDates = [
    new Date(2018,3,2),
    new Date(2018,2,30),
    new Date(2018,4,28),
    new Date(2018,7,27),
  ];

  
  christmasDates = [
          new Date(2018,11,17),
              new Date(2018,11,18),
              new Date(2018,11,19),
              new Date(2018,11,20),
              new Date(2018,11,21),
              new Date(2018,11,22),
              new Date(2018,11,23),
              new Date(2018,11,24),
              new Date(2018,11,25),
              new Date(2018,11,26),
              new Date(2018,11,27),
              new Date(2018,11,28),
              new Date(2018,11,29),
              new Date(2018,11,30),
              new Date(2018,12,31),
              new Date(2019,0,01),
              new Date(2019,0,02),
              new Date(2019,0,03),
              new Date(2019,0,04),
              new Date(2019,0,05),
              new Date(2019,0,06),
              new Date(2019,0,07),
              new Date(2019,0,08),
              new Date(2019,0,09),
              new Date(2019,0,10),
        ];

  $.merge(disabledDates, christmasDates);

For some reason, 31st December's month is 11 instead of 12, any help here would be hugely appreciated!

Comments