| View previous topic :: View next topic |
| Author |
Message |
DJAnonimo
Joined: 10 Sep 2006 Posts: 146
|
Posted: Sun Mar 30, 2008 1:43 am Post subject: Time calculations... |
|
|
Hi,
how to
"13:42:00" + "3:48"
result must be 13:45:48
thanks |
|
| Back to top |
|
 |
slomz
Joined: 03 Sep 2006 Posts: 608 Location: Iowa, U.S.
|
Posted: Sun Mar 30, 2008 1:54 am Post subject: |
|
|
You can set each hour, minute and second as seperate variables. Than add you time ass a variable also. I am sure there are faster and better ways but that is just what came to mind first. _________________
 |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 556 Location: MN, USA
|
Posted: Sun Mar 30, 2008 2:15 am Post subject: |
|
|
| Code: | var = 20080101134200
var += 3, Minutes
var += 48, Seconds
FormatTime, var, %var%, H:mm:ss
MsgBox,% var |
_________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
DJAnonimo
Joined: 10 Sep 2006 Posts: 146
|
Posted: Sun Mar 30, 2008 2:30 am Post subject: |
|
|
thanks guys  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sun Mar 30, 2008 3:14 am Post subject: |
|
|
A little more general function, which handles single digit values and arbitrary delimiters: | Code: | MsgBox % timeadd("13:42:0","3:48") ; 13:45:48
MsgBox % timeadd("1-12","1-3-48","-") ; 1-05-00
timeadd(x,y,delim=":") {
a := b := 0, c := 20010101 ; 2001 January 1st
StringSplit x, x, %Delim%
Loop %x0%
a := a*60 + x%A_Index% ; x -> a [seconds]
StringSplit y, y, %Delim%
Loop %y0%
b := b*60 + y%A_Index% ; y -> b [seconds]
c += a, Seconds
c += b, Seconds ; c <- up/date
FormatTime t, %c%, H%Delim%mm%Delim%ss
Return t
} |
|
|
| Back to top |
|
 |
DJAnonimo
Joined: 10 Sep 2006 Posts: 146
|
Posted: Sun Mar 30, 2008 3:26 am Post subject: |
|
|
Nice,
now im wondering how to subtract..
any idea ? =) |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sun Mar 30, 2008 3:45 am Post subject: |
|
|
Replace "+" with "-" in | Code: | | b := b*60 + y%A_Index% |
|
|
| Back to top |
|
 |
DJAnonimo
Joined: 10 Sep 2006 Posts: 146
|
Posted: Sun Mar 30, 2008 2:06 pm Post subject: |
|
|
Nice
thanks a lot guys |
|
| Back to top |
|
 |
|