0

I have three columns - a start date/time, an end date/time, and a duration. I found a guide for setting up the duration column to calculate plain text based on the time/date columns, but something in the syntax appears to glitch on a few of the items that last precisely one hour.

Can anyone help me spot the error here? This is the formula I'm using.

=CONCATENATE(IF(INT(([End Date and Time]-[Start date and time])*24)>0,CONCATENATE(INT(([End Date and Time]-[Start date and time])*24)," ",IF(INT(([End Date and Time]-[Start date and time])*24)>1,"hours","hour")),""),IF(MINUTE([End Date and Time]-[Start date and time])>0,CONCATENATE(" ",MINUTE([End Date and Time]-[Start date and time])," ",IF(MINUTE([End Date and Time]-[Start date and time])>1,"minutes","minute")),""))

Same formula, more readable.

=CONCATENATE(
    IF(INT(([End Date and Time]-[Start date and time])*24)>0,
        CONCATENATE(
            INT(([End Date and Time]-[Start date and time])*24),
            " ",
            IF(INT(([End Date and Time]-[Start date and time])*24)>1,
                "hours",
                "hour"
            )
        ),
        ""
    ),
    IF(MINUTE([End Date and Time]-[Start date and time])>0,
        CONCATENATE(
            " ",
            MINUTE([End Date and Time]-[Start date and time]),
            " ",
            IF(MINUTE([End Date and Time]-[Start date and time])>1,
                "minutes",
                "minute"
            )
        ),
        ""
    )
)

Thanks!

Screenshot of missing durations

1 Answer 1

0

Due to the way time differences are handled, you need to add the case when the duration is 1 hour.

Here is your corrected code:

=CONCATENATE(
    IF(INT(([End Date and Time]-[Start date and time])*24)>0,
        CONCATENATE(
            INT(([End Date and Time]-[Start date and time])*24),
            " ",
            IF(INT(([End Date and Time]-[Start date and time])*24)>1,
                "hours",
                "hour"
            )
        ),
        ""
    ),
    IF(MINUTE([End Date and Time]-[Start date and time])>=0,
        CONCATENATE(
            " ",
            MINUTE([End Date and Time]-[Start date and time]),
            " ",
            IF(MINUTE([End Date and Time]-[Start date and time])<>1,
                "minutes",
                "minute"
            )
        ),
        ""
    )
)

Try this and let me know.

1
  • 1
    That did the trick! Thank you so much. I was puzzling over that for quite a while.
    – SPgrunt05
    Commented Jan 25 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.