• Resolved giuseppe65

    (@anguria65)


    Hi,
    is it possible to set a field to add or subtract two fields with hours and minutes?
    For example:
    fieldname1: 08:00
    fieldname2: 16:00
    fieldname3 (calculated): 24:00
    fieldname4 (calculated): 08:00

    I set the formula:
    GETDATETIMESTRING(DATETIMESUM(fieldname1, ‘hh:ii’, fieldname3, ‘hh:ii’), ‘hh:ii’)
    but the result is incorrect.

    Thank you`

    • This topic was modified 2 years, 1 month ago by giuseppe65.
    • This topic was modified 2 years, 1 month ago by giuseppe65.
    • This topic was modified 2 years, 1 month ago by giuseppe65.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @anguria65

    The equations code depends on the fields fieldname1 and fieldname2. If fieldname1 and fieldname2 are text fields with values in time format, you can implement the equation as follows:

    DECIMALTOTIME(TIMETODECIMAL(fieldname1|r, 'hh:ii', 's')+TIMETODECIMAL(fieldname2|r, 'hh:ii', 's'), 's', 'hh:ii')

    and

    DECIMALTOTIME(ABS(TIMETODECIMAL(fieldname1|r, 'hh:ii', 's')-TIMETODECIMAL(fieldname2|r, 'hh:ii', 's')), 's', 'hh:ii')

    Respectively.

    Components like TIMETODECIMAL(fieldname1|r, 'hh:ii', 's') take the raw value of the field and transform the from hours:minutes format to seconds.

    The DECIMALTOTIME operation transforms the values in the other direction, takes the integer value in seconds, and transforms it into a text with the hours:minutes format.

    If fieldname1 and fieldname2 are DateTime fields with the date component disabled and the time component enabled, you can modify the equations as follows:

    DECIMALTOTIME(TIMETODECIMAL(fieldname1|r.split(' ')[1], 'hh:ii', 's')+TIMETODECIMAL(fieldname2|r.split(' ')[1], 'hh:ii', 's'), 's', 'hh:ii')

    and

    DECIMALTOTIME(ABS(TIMETODECIMAL(fieldname1|r.split(' ')[1], 'hh:ii', 's')-TIMETODECIMAL(fieldname2|r.split(' ')[1], 'hh:ii', 's')), 's', 'hh:ii')

    Best regards.

    Thread Starter giuseppe65

    (@anguria65)

    Hello @codepeople,
    It works perfectly.
    Thank you very much.

    • This reply was modified 2 years, 1 month ago by giuseppe65.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Calculate hours and minutes’ is closed to new replies.