I've a column D in a list of type Date and Time which takes only date values (not time). I want to write a javascript function to check if the value in D is less than today's date (only date, not time). I can't use the getTime() function as it also takes the time component of the date variable.


1 Answer 1


there are many available on internet. Try this for starter:

    function checkDateInpuWithTodays() {
 //get today's date in string
 var todayDate = new Date();
 //need to add one to get current month as it is start with 0
 var todayMonth = todayDate.getMonth() + 1;
 var todayDay = todayDate.getDate();
 var todayYear = todayDate.getFullYear();
 var todayDateText = todayDay + "/" + todayMonth + "/" + todayYear;

//get date input from SharePoint DateTime Control
 var inputDateText = document.getElementById('<%= datepicker.ClientID %>' + '_' + '<%= datepicker.ID %>' + 'Date').value;

//Convert both input to date type
 var inputToDate = Date.parse(inputDateText);
 var todayToDate = Date.parse(todayDateText);

//compare dates
 if (inputToDate > todayToDate) {alert("the input is later than today");}
 else if (inputToDate < todayToDate) {alert("the input is earlier than today");}
 else {alert("the input is same as today");}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.