I am looking for a simple function where I can pass in a string of a day for the current week, and it returns the calendar date number. For example, today, Monday June 28th. If I pass a string into the function, say, "MON", it should return 28.
source https://www.c-sharpcorner.com/UploadFile/8911c4/how-to-compare-two-dates-using-javascript/
For additional context, my end goal is to simply compare the current date with a chosen date, so see if it is in the past. I'm not really using built in date functions because the premise is that we are always in the current week and current month and current year. So all of that is already accounted for.
var currentDate = new Date();
var selectedCount = $('[id*=_WRAPPER]:has(.ncp-time) input[id]:selected').length;
var selectedDay = $('label[for=' +$('[id*=_WRAPPER]:has(.npc-time) :radio[id]:checked').attr('id') + ']').text().split('~')[0];
var selectedHour = $('label[for=' +$('[id*=_WRAPPER]:has(.npc-time) :radio[id]:checked').attr('id') + ']').text().split('~')[1].split(':')[0];
var selectedMinute = $('label[for=' +$('[id*=_WRAPPER]:has(.npc-time) :radio[id]:checked').attr('id') + ']').text().split('~')[1].split(':')[1];
if (selectedCount === 0) {
AlertMessage();
} //Alert message
function CompareDate() {
// new Date(Year, Month, Date, Hr, Min, Sec);
var currentDate = new Date();
//var chosenDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDay(), 12, 10, 00);
var currentDate = new Date();
var chosenDate = "chosenDate";
var selectedCount = $('[id*=_WRAPPER]:has(.ncp-time) input[id]:selected').length;
//MON~10:00
var selectedDay = $('label[for=' +$('[id*=_WRAPPER]:has(.npc-time) :radio[id]:checked').attr('id') + ']').text().split('~')[0];
var selectedHour = $('label[for=' +$('[id*=_WRAPPER]:has(.npc-time) :radio[id]:checked').attr('id') + ']').text().split('~')[1].split(':')[0];
var selectedMinute = $('label[for=' +$('[id*=_WRAPPER]:has(.npc-time) :radio[id]:checked').attr('id') + ']').text().split('~')[1].split(':')[1];
if (chosenDate < currentDate) {
alert("chosenDate is less than currentDate.");
}else {
alert("currentDate is greater than chosenDate.");
}
}
CompareDate();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="_WRAPPER"><span class="ncp-time"></span>
<input type="radio" name="Q26" value="3" id="Q26_3" role="radio" aria-checked="true" checked="checked" class="checked"><label for="Q26_3" class="choice-text">MON~10:00<a class="groupx003"></a></label></div>