How to Extract Time from DateTime field?

  • Profile Image
    Asked 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?


  • Profile Image
    Answered 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



  • Profile Image
    Answered 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).


  • Profile Image
    Answered 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 :

    Please let us know if this addresses your scenario.

  • Profile Image
    Answered 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?



  • Profile Image
    Answered 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:

    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.