Good evening team,
I have an issue with an if statement in the front end html page of my apps script
I have a date picker which i select the date, and then i can see the logged date in the console.
Then i have a new Date variable for today, so i can use the if statement to compare the selected date from the picker against today and if the selected day is less than today to stop the function and inform the user with and alert. i log the new date variable too.
The comparison doesn;t seem to work though and the function runs even if i select dates in the past.
Here is the code:
the date picker with an input html element:
<td>
<label>Date:</label><input type="date" id="date1">
</td>
then i get the value with the var date01 in my code:
var date01 = document.getElementById("date1").value;
Then i declare the today date with the following format:
var dt = new Date();
var mn = dt.getMonth() + 1;
var dt1 = (dt.getDate()<10?"0":"") + dt.getDate() + "-" + mn + "-" + dt.getFullYear();
I log both :
console.log(date01);
console.log(dt1);
Then i introduce the if statement:
if (date01 < dt1){
return("You have selected a past date") && alert("You have selected a date from the past!! Correct and resend your notification");
}
In the console both dates are logged:
2022-11-01 userCodeAppPanel:41
03-11-2022 userCodeAppPanel:42
The first date is the picker date and the second is the today date; the selected date is earlier than today but the function runs.
Any suggestions guys??
thanks in advance