boniakowski Posted July 10, 2014 Share Posted July 10, 2014 Please I need to subtract two times and I fail to understand how. example: I have a start time: 00:00:00 and a final time: 00:00:10 the final time I subtract 3 seconds or is 00:00:03 so my end result will be the final time -3 seconds 00:00:10 - 00:00:03 = 00:00:07 as I should since I've tried tickstotime timetoticks etc and I fail to deduce how to do it simply. thank you very much again for your help. Link to comment Share on other sites More sharing options...
JohnOne Posted July 10, 2014 Share Posted July 10, 2014 _DateDiff Possibly. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
boniakowski Posted July 10, 2014 Author Share Posted July 10, 2014 (edited) _DateDiff Possibly. i don´t think so, because use date start and i´m looking only time this is the help of _DateDiff $sStartDate Input Start date in the format "YYYY/MM/DD[ HH:MM:SS]" $sEndDate Input End date in the format "YYYY/MM/DD[ HH:MM:SS]" Edited July 10, 2014 by boniakowski Link to comment Share on other sites More sharing options...
JohnOne Posted July 10, 2014 Share Posted July 10, 2014 #include <Date.au3> #include <MsgBoxConstants.au3> ; subtract 3 seconds from current time $sNewDate = _DateAdd('s', -3, _NowCalc()) MsgBox($MB_SYSTEMMODAL, "", "Current time -3 seconds: " & $sNewDate) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Solution jguinch Posted July 10, 2014 Solution Share Posted July 10, 2014 (edited) #Include <Date.au3> $diff1 = _TimeDiff("00:00:10", "00:00:03") ConsoleWrite($diff1 & @CRLF) Func _TimeDiff($sTime1, $sTime2) Local $iH, $iM, $iS If NOT StringRegExp($sTime1 & "-" & $sTime2, "\d\d:\d\d:\d\d-\d\d:\d\d:\d\d") Then Return SetError(1, 0, 0) Local $iDiff = _DateDiff( "s", "1970/01/01 " & $sTime1, "1970/01/01 " & $sTime2) & 100 _TicksToTime( Abs($iDiff), $iH, $iM, $iS) If @error Then Return SetError(2, 0, 0) Local $sReturn = StringFormat("%02s", $iH) & ":" & StringFormat("%02s", $iM) & ":" & StringFormat("%02s", $iS) If $iDiff > 0 Then $sReturn = "-" & $sReturn Return $sReturn EndFunc Edited July 10, 2014 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
boniakowski Posted July 10, 2014 Author Share Posted July 10, 2014 #include <Date.au3> #include <MsgBoxConstants.au3> ; subtract 3 seconds from current time $sNewDate = _DateAdd('s', -3, _NowCalc()) MsgBox($MB_SYSTEMMODAL, "", "Current time -3 seconds: " & $sNewDate) Ok your example work fine but always with a date _NowCalc() return date format, i don´t need a date format, i only need a Result of TIME in seconds. $StartTime=("00:00:00") $StopTime=("00:00:10") $Difference=("00:00:03") $Result=($StopTime-$Difference) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 10, 2014 Moderators Share Posted July 10, 2014 Something like this, perhaps? I'm sure a RegEx master will wander by to improve: #include <Date.au3> $startTime = _NowTime(5) $finishTime = StringLeft($startTime, 6) & (StringRight($startTime, 2) - 3) MsgBox(0, $startTime, $finishTime) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JohnOne Posted July 10, 2014 Share Posted July 10, 2014 Ok your example work fine but always with a date _NowCalc() return date format, i don´t need a date format, i only need a Result of TIME in seconds. $StartTime=("00:00:00") $StopTime=("00:00:10") $Difference=("00:00:03") $Result=($StopTime-$Difference) It's just a bit of jiggery pokery to get it how you want. Have a try to make a function which takes hh:mm:ss and returns same. The function can add yyyy/mm/dd to do the calcs and remove it to return what you need. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
boniakowski Posted July 10, 2014 Author Share Posted July 10, 2014 #Include <Date.au3> $diff1 = _TimeDiff("00:00:10", "00:00:03") ConsoleWrite($diff1 & @CRLF) Func _TimeDiff($sTime1, $sTime2) Local $iH, $iM, $iS If NOT StringRegExp($sTime1 & "-" & $sTime2, "\d\d:\d\d:\d\d-\d\d:\d\d:\d\d") Then Return SetError(1, 0, 0) Local $iDiff = _DateDiff( "s", "1970/01/01 " & $sTime1, "1970/01/01 " & $sTime2) & 100 _TicksToTime( Abs($iDiff), $iH, $iM, $iS) If @error Then Return SetError(2, 0, 0) Local $sReturn = StringFormat("%02s", $iH) & ":" & StringFormat("%02s", $iM) & ":" & StringFormat("%02s", $iS) If $iDiff > 0 Then $sReturn = "-" & $sReturn Return $sReturn EndFunc It´s i am looking for, thanks for your help. Thanks too guys: JohnOne JLogan3o13 yours answers help to open my mind too. Thank tou very much. Solved. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now