Search code examples
angularjsdatepickerdaterangepicker

date-range picker picks date of the day before


I am using angular daterange picker to pick one date and here is how my html looks like:

<input date-range-picker ng-model="model" options="{singleDatePicker: true}"
       class="form-control date-picker" type="text"/>

Now when I select a date when the calender pops up, it selects the date apparently but when it is sent to backend, it is actually the date of one day before. i.e, If I select 28-02-2020 it will send 27-02-2020. Also, I just want the datepicker to send just the date, currently it sends it something like this:

2020-02-27T19:00:00.000Z 

What am I doing wrong here? Any help?


Solution

  • You can add your timezone to date by using the following way,

    var d = new Date('yourDate');
    d.setMinutes( d.getMinutes() + d.getTimezoneOffset() );
    
    'd' should be the correct date
    

    Or

    You can also check by simply doing like 'Your Date'.toISOString()