2

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.

Kay
  • 393
  • 1
  • 14

1 Answers1

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");}
 }
Ankit Kumar
  • 1,768
  • 1
  • 15
  • 34