When users are selecting a date i want the date to be between a range. e.g they can only select from 1st jan to 2nd march nothing else. Is there a way to be able to add this into the date field?

  • 1
    In that case you can you some custom datepicker rather than using default SP datepicker. – Atish Dipongkor - MVP Nov 24 '15 at 7:36

If you want to use the OOTB datefields you could probably just change the minjday and maxjday for the picker, but that only restricts the picker. They could still write a date that is not in the picker range, for that you'll have to add a change handler to the field. There is also a property called onvaluesetfrompicker if i remember correctly that could be used.

Simple example for restricting the picker:

var getSPDayDiff = function(date) {
    return Math.round(Math.abs( ( new Date(1601,0,1).getTime() - date.getTime())/( 24*60*60*1000 ) ) );

var minDay = getSPDayDiff( new Date(2015,0,1) );
var maxDay = getSPDayDiff( new Date(2015,2,2) );                

var $trDateTimeControl = $("input[id='"+ g_strDateTimeControlIDs["SPDateField1"] + "']").closest("tr");

var dateTimeHtml = $trDateTimeControl.find(".ms-dtinput:eq(1)").html();
dateTimeHtml = dateTimeHtml.replace("minjday=109207", "minjday="+minDay);
dateTimeHtml = dateTimeHtml.replace("maxjday=2666269", "maxjday="+maxDay);

$trDateTimeControl.find(".ms-dtinput:eq(1)").html( dateTimeHtml );

minjday and maxjday are number of days sine 1/1/1601.

| improve this answer | |
  • Hi Anders can i use this on an infopath form? – naijacoder Nov 24 '15 at 22:44
  • For InfoPath I don't know @naijacoder – Anders Aune Nov 25 '15 at 7:42
  • I also have requirement where i should disable the pastdates and also current date in date picker ,allowing user to pick the date that is not less than today. ![sharepoint date time control](i.stack.imgur.com/zjyby.png) when i inspect the element of date icon i seen following code: a **onclick**="**clickDatePicker**("ctl00_ctl39_g_1520de65_6f70_4c7f_b7b2_5578a563acda_ff241_ctl00_ctl00_ctl00_startDateTimeControl_startDateTimeControlDate", "\u002fsites\u002fPSEGPublishingsite\u002f_layouts\u002f15\u002fiframe.aspx?&cal=1&lcid=1033&langid=1033&ww=011 – Swetha Paritala Nov 18 '17 at 19:41
  • @SwethaParitala Please if you have a new question you can post it here – Mohamed El-Qassas MVP Nov 19 '17 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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