MatBlazor icon indicating copy to clipboard operation
MatBlazor copied to clipboard

MatDatePicker subtracts 1 day from selected date

Open ClumsyMonkey opened this issue 4 years ago • 10 comments

Description This issue have been talked about before, but from what Im seeing the bug is still here. Its very simple: Add MatDatePicker component and select a date. The output is selected date - 1 day. Using the ToLocale does not seem to fix the issue. On my local machine it works fine but when I upload to Azure the bug starts to show. The number you select in the datepicker should reflect the output.

Steps to reproduce the behavior:

  1. Create a new project and install the MatBlazor package.
  2. Add MatDatePicker to a page.
  3. Select a date

In this example I select the 23rd. The code was uploaded to an Azure web app so this example is not from my locale machine.

Screenshots image

image

ClumsyMonkey avatar Sep 21 '20 12:09 ClumsyMonkey

Can confirm too. Happens locally and on my server. I also tried overriding the Format property on MatDatePicker in multiple ways and always yields date -1.

I've tried stepping through some of the Flatpickr and matblazor JS and it looks like the correct date is being passed there; the pop-up shows the correct date and the text field is minus 1 day.

gismofx avatar Oct 20 '20 02:10 gismofx

I am also getting this issue when selecting a date a -1 value is set on the bound field

Christoffleroux avatar Oct 23 '20 04:10 Christoffleroux

For me it's always setting time to 10 PM (I have time picker completely disabled too, only date) and thus it also results in setting -1 day than selected. The date is set to UTC.

However in my case calling date.ToLocalTime() sets the time back to 00:00:00 (from 10:00:00 PM) so it kind of works around the issue. But definitely needs a long term fix ASAP

rsobon avatar Oct 26 '20 10:10 rsobon

And there are two similar cases:

  • at MatBlazor site DatePicker yields selected date -1 and shows it with that new value;
  • in my proj DatePicker does things equal, but shows correct date (and sets yieded date to binded value)

Ладно, мой английский заставляет страдать, так что на всякий случай пишу ещё и так. Наблюдаю два схожих случая:

  • на Вашем сайте MatBlazor DataPicker устанавливает значение со сдвигом на -1 и отображает его уже сдвинутым;
  • в моём проекте он всё так же устанавливает забинженое значение со сдвигом на -1, но отображает при этом корректную дату

Nerewan avatar Dec 08 '20 13:12 Nerewan

This worked for me: ExampleDate = ExampleDate.Value.AddDays(0).ToLocalTime();

Albertoenriquepaulo avatar Aug 27 '21 13:08 Albertoenriquepaulo

for me in the datepicker(ui) it shows 2nd Feb but when I am fetching the value from formControl it subtracts 1 from days.

The display and the fetched values should be same.

shantammittal avatar Jan 04 '22 13:01 shantammittal

In my case worked the following:

  • yourDate.toLocaleDateString() --> DD/MM/YYYY
  • yourDate.toLocaleString() --> DD/MM/YYYY HH:mm:ss

jdnav avatar May 09 '22 12:05 jdnav