Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Set Start date issue (skips one entire month) if previous month has 31 days #208

Open
Sagrevel opened this issue Apr 2, 2019 · 4 comments
Labels

Comments

@Sagrevel
Copy link

Sagrevel commented Apr 2, 2019

Datepicker version 1.0.7

Greetings:

I'm working with two datepicker elements to select start and end dates, the second one's start date is setting up as the selected date in the first one (and loking previous dates to be selected), all seem to be OK until I selected the first day for the following months as 'From' date:

April, June, October and November (I don't know if is the issue is because these months have 31 days, I looked other issue reports and I found this one https://github.com/fengyuanchen/datepicker/issues/195 but no more details have been added)

After pick it, all the dates for the months mentioned are locked and only dates starting one month after are available to select in the 'To' field (May, July, November and December ).

Is important to mention that if I select the second day instead 1st one for the months mentioned all work fine (in other words the issue only is presented when I select 1st day, the year is not a factor; please see attached pictures).

Issue example (selecting April 1st 2018 all April dates are locked in the second datepicker)
Issue example

_Selecting April 2nd (Starting date set correctly in the second datepicker) _
Without Issue

Finally, as reference the code I'm using:

For the datepickers inicialization

/*Datepicher 'From'*/
$('#datep').datepicker({
       format: 'yyyy-mm-dd', 
       autoShow: false, 
       date: Date.now(),
});

/*Datepicher 'To'*/
$('#datep2').datepicker({
       format: 'yyyy-mm-dd', 
       autoShow: false, 
       date: Date.now(),
});

For setting the startdate of datepicker 'To' (locking all the previous dates):

$(document).on('change', '#datep', (e) => {
       e.preventDefault();
       const date = $(e.target).val();
       $('#datep2').datepicker('setStartDate', date);
});

Thanks

@fengyuanchen
Copy link
Owner

Cannot reappear the bug. Can you provide an online demo on CodePen or others?

@Raayen
Copy link

Raayen commented Aug 31, 2021

I have the same problem and know what is causing it: the conversion to different languages/dates.

I have two calendars. The second one gets the startDate from the first calendar. But if i set the first calendar to '14.09.2021' (14th September), the second calendar starts on '14.10.2021' (14th October). So it skips an entire month.

I only get this problem when working with 'de-DE' language. Even when I use following methods:
jQuery(this).datepicker('setStartDate', '14.09.2021'); //September
jQuery(this).datepicker('setDate', '14.09.2021'); //September

So I hardcoded the date and it still shows '14.10.2021'. //October

But when I use default english settings, this works perfectly fine:
jQuery('.uBis').datepicker('setStartDate', '09-14-2021');//September
jQuery('.uBis').datepicker('setDate', '09-14-2021');//September

Can you please take a look at the problem, I really need to work with german language asap. Would really help me out :)

Thank you

@anas510
Copy link

anas510 commented Mar 31, 2022

Exact same issue for me and I am using latest version 1.0.10
In english it works fine but for german it isn't and issue happens for Feb, Apr, Jun, Sep and Nov

@anas510
Copy link

anas510 commented Mar 31, 2022

The fix for this issue is very simple, this issue happens when current-date is greater then the max-date of month to which you are changing your date.
e.g: if we change date on 31st march to any date in May

To fix this, you can update datepicker.js file:
find "parseDate" and update date.setMonth(value-1) to date.setMonth(value-1,1)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants