Into NewForm.aspx I have Date and Time field, which I disabled via jQuery.

My computer is set to 14:46, so I will receive 14:45 in SharePoint. Hour is correct but minutes are not; it is always set as 00.

Column Setting

List column settings

Field in NewForm.aspx

Field in NewForm.aspx dialog

JS to disable date and time column

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
     var itemID = $("input[title='Fecha']").attr("id");

// Trim the Item ID and keep the first part which is common for each element of this DatePicker

    var itemCode = itemID.substring(0, itemID.indexOf('$'));

    // Set text input to readOnly  

    $( "[id^=" + itemCode + "] td.ms-dtinput > input[id$='Date']" ).attr('readonly', 'readonly');


    $( "[id^=" + itemCode + "] td.ms-dtinput > input[id$='Date']" ).attr('disabled', 'disabled');

    // Disable the onclick action on the button

    $( "[id^=" + itemCode + "] td.ms-dtinput > a" ).attr('onclick','').unbind('click');

    // Disable the 2 time select elements

    $( "[id^=" + itemCode + "] td.ms-dttimeinput > select[id$='DateHours']" ).attr('disabled', 'disabled');

    $( "[id^=" + itemCode + "] td.ms-dttimeinput > select[id$='DateMinutes']" ).attr('disabled', 'disabled');

});

</script>

Regards.

up vote 2 down vote accepted

If you instead use the calculated value default value option, and set it to NOW(), this will set the date, plus hour and time. Keep in mind the hour may not match your local time, based on your time zone settings, but I just confirmed the use of now() will set the minute value correctly.

Cheers, Matt

enter image description here

  • Best solution, I was thinking about set something like DateTime.Now.Utc with javascript, but your solution is the best – Ledwing Sep 1 '17 at 20:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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