Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare selected date with date today #58

Closed
stkol76 opened this issue Oct 21, 2021 · 1 comment
Closed

Compare selected date with date today #58

stkol76 opened this issue Oct 21, 2021 · 1 comment

Comments

@stkol76
Copy link

stkol76 commented Oct 21, 2021

Hi @mikecoj

I hope you can help me .. I have tried to compare the date selected in MCDatepicker using the onSelect() event hook and todays date using jQuery, but so far unsuccessfully .. how can I do this? .. I have also made a post on StackOverflow without any response here : https://stackoverflow.com/questions/69653851/how-can-i-check-if-selected-date-in-mcdatepicker-is-today%c2%b4s-date

Hope you can help me :-)

Best Regards
Stig

@mikecoj
Copy link
Owner

mikecoj commented Oct 21, 2021

Hey @stkol76,

onSelect() hook passes a date object as an argument to its callback function, so you can use any method of the date object.
To compare 2 dates you need to convert them into numbers, you can use the valueOf() method for this.
ex:

datepicker.onSelect((date)=>{
    const newDate = new Date()
    if(date.valueOf() < newDate.valueOf()) console.log("The date is in the past!")
})

@mikecoj mikecoj closed this as completed Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants