3

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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Saani
  • 791
  • 7
  • 28
  • 68

2 Answers2

4

With AngularJS, date pickers need to set the ng-model-options timezone to UTC:

<input type="date" ng-model="pickedDate" ng-model-options="{timezone: 'utc'}">

For more information, see

The DEMO

<script src="//unpkg.com/angular/angular.js"></script>

<body ng-app>
    <h1>Hello Plunker!</h1>
    <input type="date" ng-model="pickedDate" ng-model-options="{timezone: 'utc'}">
    <br>
    pickedDate={{pickedDate}}
</body>
Community
  • 1
  • 1
georgeawg
  • 48,608
  • 13
  • 72
  • 95
1

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()

Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43