What value are you getting for dateSelected?
May 21, 2021
6
Level 2
Compare date now and user date input.
I'm trying to compare if 2 dates are equal by converting them to string, but whether they are equal or not it is returning the same results. Are there any fixes or alternatives?
This is my code.
var current = new Date();
var month = current.getUTCMonth() + 1;
var day = current.getUTCDate();
var year = current.getUTCFullYear();
var dateToday = year + "-" + month + "-" + day;
//User's select date
var dateSelected=$('#date').val();
var sDateToday = dateToday.toString();
var sDateSelected = dateSelected.toString();
Level 2
Thanks for the reps. I was able to solve it with this
function compareDates() {
var date = .getElementById('date').value;
var inpDate = new Date(date);
var currDate = new Date();
if(inpDate.setHours(0, 0, 0, 0) ==
currDate.setHours(0, 0, 0, 0))
{
console.log('Equal');
}
Please or to participate in this conversation.