Calculate time between dates Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
N_athan
Posts: 40
Joined: 21 Aug 2021, 16:40

Calculate time between dates

Post by N_athan » 27 Sep 2021, 14:33

How do I need to format the date to get the minutes between them?

Ex:

Code: Select all

date1 = 26-09-2021 14:23:00
date2 := A_Now
EnvAdd, date2, +3, hour
FormatTime,NewTime,%date2%,HH:mm:ss
MsgBox %date2%
.....
I need to add a +3 to my current time.
Then I get how many minutes have passed since the date1.

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Calculate time between dates  Topic is solved

Post by mikeyww » 27 Sep 2021, 14:45

Code: Select all

date = 26-09-2021 14:23:00
MsgBox, 64, Result, % "Minutes since " date ":`n`n" minsSince(date, 3)

minsSince(date, offsetHours := 0) {
 date := RegExReplace(date, "[- :]")
 mins += offsetHours, H
 mins -= SubStr(date, 5, 4) SubStr(date, 3, 2) SubStr(date, 1, 2) SubStr(date, 9), M
 Return mins
}

N_athan
Posts: 40
Joined: 21 Aug 2021, 16:40

Re: Calculate time between dates

Post by N_athan » 27 Sep 2021, 15:18

@mikeyww how to deduct hours from this variable:

Code: Select all

hour:= 15:00:00
EnvAdd, hour, -3, hour
FormatTime,hour,%hour%, HH:mm:ss
MsgBox %hour%

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Calculate time between dates

Post by mikeyww » 27 Sep 2021, 15:54

Code: Select all

time = 15:00:00
MsgBox, 64, Adjusted time, % addHours(time, -3)

addHours(time, offsetHours) {
 date := 20210927 StrReplace(time, ":")
 date += offsetHours, H
 FormatTime, time, %date%, HH:mm:ss
 Return time
}

Post Reply

Return to “Ask for Help (v1)”