Jump to content
Sign in to follow this  
Vladi243

Hours difference

Recommended Posts

Vladi243

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 this post


Link to post
Share on other sites
i542

_DateDiff UDF.


I can do signature me.

Share this post


Link to post
Share on other sites
Vladi243

_DateDiff UDF.

Can you give me an example?

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

Share this post


Link to post
Share on other sites
i542

Can you give me an example?

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

Thats the one :mellow:

I can do signature me.

Share this post


Link to post
Share on other sites
Malkey

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

http://www.autoitscript.com/forum/index.ph...st&p=592906

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×