Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |

Friday, July 18, 2014

sharepoint datetimecontrol validation using JQuery

This post helps us on below mentioned validations.
  1. Required validation.
  2. Selected date time cannot be less than current date


//To get the selected date time control value

var selectedDateTimeVal = $('input[id*="dtcDateTimeCtrl"]').val();

//Required validation

if (selectedDateTimeVal == '') {
  
alert("Date Time control field value is required");

}

else
{
 var date = new Array();

 var currDate = new Date();

 // Input date format : mm/dd/yyyy

 date = selectedDateTimeVal.split('/');

 var year = date[2];

 var month = date[1];

 var date = date[0];

 var selectedDate = month + "/" + date + "/" + year;

 var tarDate = new Date(selectedDate);

 var timeDiff = tarDate.getTime() - currDate.getTime();

 var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

 if (parseInt(diffDays) < 0) {

  alert("Selected datetime value cannot be less than current date");

  }
}

1 comment:

  1. Can you pls help, by using moment.js file , to compare tow datetimefields? i have 2 DT fields, and i need to compare these 2 and if one is greater than other i need to return false in my presaveaction call.

    ReplyDelete