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.
Asked
Active
Viewed 886 times
2
-
1For date functions I've used the moment.js library. http://momentjs.com/ – Lost in Alabama Aug 04 '16 at 13:29
-
Also read: http://sharepoint.stackexchange.com/questions/151144/how-to-use-today-and-me-in-calculated-column/151336#151336 – Danny '365CSI' Engelman Aug 04 '16 at 15:52
1 Answers
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