I am trying to get the time selected from SharePoint list and store it one variable. I have attached an image for reference, Can anyone help me with this?enter image description here


No need to use the jquery, you can do that using vanilla JS querySelector

var time =   document.querySelector("select[id='Scheduled_x0020_time_0c63521b-1292-45ae-a881-f85e14c83ca7_$DateTimeFieldDateHours'").value + ":" + document.querySelector("select[id='Scheduled_x0020_time_0c63521b-1292-45ae-a881-f85e14c83ca7_$DateTimeFieldDateMinutes'").value 


The datetime field has two select controls to show the time value

  • DateTimeFieldDateHours for Hours
  • DateTimeFieldDateMinutes for Minutes

So you are trying to query the selector with the actual ID id=, or using contains id=^ then try to concatenate both values to get the desired value as shown below.


enter image description here

| improve this answer | |
  • Thank you for the answer, will try this and let you know. – Prashanth Edige Sep 13 '18 at 13:21

Mohamed's code is right, if you want to use jQuery code, check the code below.

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
    var fieldName="Select Scheduled Departure Time";
    var fieldDateHours=$(".ms-standardheader:contains('"+fieldName+"')").closest("tr").find("select[id$='_$DateTimeFieldDateHours']").val();
    var fieldDateMinutes=$(".ms-standardheader:contains('"+fieldName+"')").closest("tr").find("select[id$='_$DateTimeFieldDateMinutes']").val();
| improve this answer | |
  • Thank you for the answer, will try this and let you know if its working. – Prashanth Edige Sep 13 '18 at 13:21
  • This function does not get triggered , I want to use this function in the change.function(). Can I use this there? – Prashanth Edige Sep 13 '18 at 19:10
  • It says Uncaught TypeError: $(...).closest is not a function. when I try to run the code which you have mentioned. – Prashanth Edige Sep 19 '18 at 20:28
  • My api request accepts 24 hour format date and I have 12 hour format date like this 9:00 PM and I need it to be as 21:00. How can I do that here in jquery? – Prashanth Edige Sep 19 '18 at 20:34

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.