What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    How to Extract Time from DateTime field?

    Asked by grade4pagasa on September 19, 2015 at 07:59 PM

    good day.  

    how do i extract the time separately using the DateTime field as my source?

    i can get the date via dateString. but how to extract the Time?

    thanks.  

    Page URL:
    http://form.jotform.me/form/52617968305463

    date and time time_value extract time
  • Profile Image

    Answered by Sammy on September 21, 2015 at 07:02 AM

    I used the sub-string widget to get the time value form a temporary text-field containing the full DateTime.

    Kindly refer to this example form for details on the conditions

    http://www.jotformpro.com/form/52632150278957

     

     

  • Profile Image

    Answered by grade4pagasa on September 21, 2015 at 10:12 PM

    thanks Sammy

    follow up question. 

    how do i extract just the hour (without the ":")?

    via the Substring field, the characters before the colon could be 1 or 2 digits (e.g., 2:00 or 12:00).

    thanks. 

  • Profile Image

    Answered by Sammy on September 22, 2015 at 03:47 AM

    We can use the mask condition to set a number mask on the input field, this way we will force the value to be auto-formatted to match the mask.

    This is the mask pattern used ####@@, first four is the numbers then the last is for the letters (AM/PM)

    Here is the link to the demo form :

    http://www.jotformpro.com/form/52632150278957

    Please let us know if this addresses your scenario.

  • Profile Image

    Answered by grade4pagasa on September 23, 2015 at 11:43 PM

    thanks again, Sammy !

    i'm just wondering why the CurrentTime substring field & InputMasked field are empty once the form is initially loaded? and that the fields will only populate when the DateTime time options are manipulated / modified (please see attached gif). 

    the DateTime field source is intended to be hidden in the real application (and just made visible in this scenario as reference).

    once the DateTime field source is hidden (and cannot be edited), how can the CurrentTime substring field & InputMasked field be automatically populated?

    thanks. 

     

  • Profile Image
    JotForm Support

    Answered by Mike_G on September 24, 2015 at 12:07 PM

    The reason why the Time field(with InputMasked) is not prepopulated when the form loads is because it waits for the CurrentTime field widget to be filled first, and that filled will only have a value in it if the TempDate is filled, the CurrentTime field will not read what's in the TempDate field but will rather check if it was updated.

    I have another workaround.

    Instead of using the Substring widget, I separated the Date field and the Time field. 

    Then, I used a Number field(TempTime) to get the value of time and since number fields only read numbers, it will omit the ":" and "AM" or "PM". so if the time is 11:42 PM, the value that will be passed to the number field is just 1142 which will solve your issue with the ":"

    Then to get the if it's AM or PM, I added another field(TestAMPM) to get the time and another field(TempAMPM) that will hold the value of "AM" or "PM". I created a condition whereas, if the Time field is filled, its value will be passed to the "TestAMPM" field. Then, another condition that states, if "TestAMPM" field contains "AM" input "AM" to "TempAMPM" field and if it contains "PM" input "PM to "TempAMPM" field.

    Then both values of TempTime field and TempAMPM will be combined in the Time textbox field using condition, then it will be passed to the Text field.

    Here's a demo .gif.

    Here's the form: http://form.jotformpro.com/form/52663190056959

    Please feel free to clone it using this guide: How-to-Clone-an-Existing-Form-from-a-URL

    I hope this helps. Should you need any further assistance, please feel free to let us know and we will be glad to help you. Thank you.