# Hours difference

## Recommended Posts

Hello,

Is there a way in autoit to calculate hours difference?

For example I want to calculate the hours difference between 12:48 and 17:27.

I need the shortest script to calculate this kind of things.

Thanks.

##### Share on other sites

_DateDiff UDF.

I can do signature me.

##### Share on other sites

_DateDiff UDF.

Can you give me an example?

I haven't found it in the help file. I only found the function _DateDiff.

##### Share on other sites

Can you give me an example?

I haven't found it in the help file. I only found the function _DateDiff.

Thats the one

I can do signature me.

##### Share on other sites

Can you give me an example?

I haven't found it in the help file. I only found the function _DateDiff.

You have probably worked this out by now.

_DateDiff() is a little tricky at first use, I found.

Here is an example for the time difference in hours and minutes.

```#include <Date.au3>

\$sFinishTime = "17:27" ; Proper format in the form of  "2008/02/01 02:15:00"
\$sStartTime = "12:48"

; Returns total number of hours only, an integer (no decimal of an hour).
\$intTotalHrDiff = _DateDiff('h', "1970/01/01 " & \$sStartTime & ":00", "1970/01/01 " & \$sFinishTime & ":00")

; Returns total number of minutes only, an integer.
\$intTotalMinDiff = _DateDiff('n', "1970/01/01 " & \$sStartTime & ":00", "1970/01/01 " & \$sFinishTime & ":00")

MsgBox(4096, "", "First Time difference  " & @CRLF & @CRLF & \$intTotalHrDiff & " hr " & _
\$intTotalMinDiff - (\$intTotalHrDiff * 60) & " min")

;=======================================================
; Above shortened
\$intTotalHrDiff = _DateDiff('h', "1970/01/01 " & \$sStartTime & ":00", "1970/01/01 " & \$sFinishTime & ":00")
\$sHrMinDiff = \$intTotalHrDiff & " hr " & _DateDiff('n', "1970/01/01 " & \$sStartTime & ":00", "1970/01/01 " & _
\$sFinishTime & ":00") - (\$intTotalHrDiff * 60) & " min"

MsgBox(4096, "", "Second Time difference  " & @CRLF & @CRLF & \$sHrMinDiff)```

An example for days,hours, and minute difference see

## Create an account

Register a new account