Skip to content

Instantly share code, notes, and snippets.

@VenkataA
Last active June 10, 2022 16:17
Show Gist options
  • Save VenkataA/9a0b678666cad22b2615f6a6d5c6dc0e to your computer and use it in GitHub Desktop.
Save VenkataA/9a0b678666cad22b2615f6a6d5c6dc0e to your computer and use it in GitHub Desktop.
JavaScript Function - Check to see if date string is less than tomorrow
//Assumes a date string yyyy-mm-dd or mm/dd/yyyy
function isGreaterThanToday(inpDateField) {
var inpDate = inpDateField.rawValue;
var todaysDate = new Date();
todaysDate.setHours(0,0,0,0);
var splitDate = inpDate.split('-');
var nYear = splitDate[0];
var nMonth = splitDate[1];
var nDay = splitDate[2];
if (splitDate.length < 3) {
splitDate = inpDate.split('/');
nYear = splitDate[2];
nMonth = splitDate[0];
nDay = splitDate[1];
}
console.println("month = " + nMonth + " day = " + nDay + " Year = " + nYear);
var enteredDateStr = nYear+"-"+nMonth+"-"+nDay;
var enteredDate = new Date(enteredDateStr );
//Store tomorrow values
var tomorrowYear = todaysDate.getFullYear();
var tomorrowMonth = todaysDate.getMonth() + 1; // 0 based
var tomorrowDay = todaysDate.getDate();
console.println("tomorrow --- " + " Month = " + tomorrowMonth + " tomorrowDay = " + tomorrowDay + " tomorrowYear = " + tomorrowYear );
if (enteredDate.getTime() > todaysDate.getTime()) return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment