DateTime Single calculations

  • TycenDemolitions
    Asked on October 22, 2018 at 9:32 PM

    Hi

    I would like to build a timesheet that calculates how many hours and minutes between two datetimes.

    I would like to add up total hours minus breaks at the end of the week and display to the user before submission.

    However i don't understand the output from the calculation when i subtract finishTime from StartTime. is there some kind of formula for working with the result of subtracting a datetime from a datetime?

    \many thanks

    Jotform Thread 1619370 Screenshot
  • BJoanna
    Replied on October 23, 2018 at 5:08 AM

    Based on my tests it is not possible to perform an accurate calculation with the DateTime Single widget. 

    If you want to calculate the hours and minutes, you should use a basic Date Picker field with enabled Time Option. Inside of the following guide, you can find how to do it:

    Mastering Date and Time Calculation

  • TycenDemolitions
    Replied on October 23, 2018 at 9:50 AM

    Thanks for testing the DateTime Single Widget, we arrived at the same conclusion :-)

    The reason i was using a DateTime Single Widget was because i had previously tried to use a proper date field with time enabled, like you suggested, but i could not get it to look right in mobile view. The date and time would split on to two lines and the time fields were not properly visible, the calendar input helper appears on a line by itself. please see part 1 of the attached image circled in red which illustrates what i mean. 1540302014Screenshot 20181024 000718 Chr Screenshot 10



    Is there a CSS trick i can apply to always make the date and time occupy one line of the form like i have pasted into the image in a red rectangle. 

    I have a lot of date and time fields in my form and users will primarily use a mobile device to fill in the forms so i would love to get them looking tidy.


    Thanks

  • BJoanna
    Replied on October 23, 2018 at 11:21 AM

    I am not sure if there is enough space for all fields to fit in the same line. Maybe if Lite Mode is enabled inside of the Date field, they can all fit in the same line. 

    Please provide us a link of the form you are working on. 

  • TycenDemolitions
    Replied on October 23, 2018 at 8:08 PM

    https://form.jotform.co/82957020267863

    In portrait view on a mobile device.

    I increased the width of the whole form to 759px and used lite mode on the date field. Now the whole field appears on one line as desired, thanks.

    However in portrait view the date portion of the field is spanning the full width of the form, pushing the time off the page as circled in red in the picture.

    can i somehow target the date fields with CSS to only to use a fixed number of pixels so that they do not auto fill the full width?

    Thanks

    1540339522Screenshot 20181024 105955 Chr Screenshot 10

  • David JotForm Support Manager
    Replied on October 23, 2018 at 11:44 PM

    Please inject the following CSS code: https://www.jotform.com/help/117-How-to-Inject-Custom-CSS-Codes 

    @media only screen and (max-width: 480px) {

    #id_4 span.form-sub-label-container{

        width: auto !important;

    }

    #id_6 span.form-sub-label-container{

        width: auto !important;

    }

    [data-type=control_datetime] .form-sub-label-container:first-child {

        margin-left: 6%;

    }

    }

    Result:

    1540352565mobile Screenshot 10