I have a Date Picker (#datePicker1) on a page, where the user chooses a "Check-In Date".
And I have a Button (#button10) - which needs to be HIDDEN / SHOWN based on the date 'PICKED' in the date-picker field.
If the user chooses a date between 1st April and 31st August - the BUTTON should be VISIBLE - Otherwise, it should be hidden.
I have managed to get it to work more or less as it should - but the 'solution' is restricted to the CURRENT YEAR...
Here's my code ~
export function datePicker1_change(event) {
var startD = new Date('04/01/2021');
var endD = new Date('08/31/2021');
var CheckIn = $w('#datePicker1').value;
if(startD >= CheckIn || endD <= CheckIn) {
$w('#button10').hide()
} else {
$w('#button10').show()
}
}
NEED HELP WITH THE FOLLOWING ~
Change the code so that it works for ANY YEAR in the future [i.e. not have it specify '2021' in the 'new Date()' parts of the code]
Make the code such that the 'new Date()' variables are BASED ON OUR LOCAL TIME (Indian Standard Time - IST) - and not affected by the Users local time (eg. a user in the US/UK)
Thanks in advance, for any help...
(NB: I am a novice at coding - so, do bear with my ignorance!)
OK, so after reading your post again, I think I understand what you're trying to do. You want to check if the checkin date in one year is between two dates of the same year. Every year, the start is April 1, and end is August 31.
Try the following:
let checkinD = new Date(2022, 5, 15); // month is zero based let year = checkinD.getFullYear(); let startD = new Date(year, 3, 1); // month is zero based ket endD = new Date(year, 7, 31); // month is zero based console.log(checkinD, startD, endD); if((checkinD.getTime() <= endD.getTime() && checkinD.getTime() >= startD.getTime())) { console.log('in'); } else { console.log('out'); }
The above code uses console.log() statements to see what's happening. You can add your hide and show as you need.
I hope this helps.