AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Time calculations...

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
DJAnonimo



Joined: 10 Sep 2006
Posts: 146

PostPosted: Sun Mar 30, 2008 1:43 am    Post subject: Time calculations... Reply with quote

Hi,

how to
"13:42:00" + "3:48"
result must be 13:45:48

thanks
Back to top
View user's profile Send private message MSN Messenger
slomz



Joined: 03 Sep 2006
Posts: 608
Location: Iowa, U.S.

PostPosted: Sun Mar 30, 2008 1:54 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
jaco0646



Joined: 07 Oct 2006
Posts: 556
Location: MN, USA

PostPosted: Sun Mar 30, 2008 2:15 am    Post subject: Reply with quote

Code:
var = 20080101134200
var += 3, Minutes
var += 48, Seconds
FormatTime, var, %var%, H:mm:ss
MsgBox,% var

_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
DJAnonimo



Joined: 10 Sep 2006
Posts: 146

PostPosted: Sun Mar 30, 2008 2:30 am    Post subject: Reply with quote

thanks guys Smile
Back to top
View user's profile Send private message MSN Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun Mar 30, 2008 3:14 am    Post subject: Reply with quote

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
View user's profile Send private message
DJAnonimo



Joined: 10 Sep 2006
Posts: 146

PostPosted: Sun Mar 30, 2008 3:26 am    Post subject: Reply with quote

Nice,
now im wondering how to subtract..

any idea ? =)
Back to top
View user's profile Send private message MSN Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun Mar 30, 2008 3:45 am    Post subject: Reply with quote

Replace "+" with "-" in
Code:
b := b*60 + y%A_Index%
Back to top
View user's profile Send private message
DJAnonimo



Joined: 10 Sep 2006
Posts: 146

PostPosted: Sun Mar 30, 2008 2:06 pm    Post subject: Reply with quote

Nice Smile

thanks a lot guys
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group