Sign in to follow this  
Followers 0
boniakowski

Subtract seconds

9 posts in this topic

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.

Share this post


Link to post
Share on other sites



#3 ·  Posted (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 by boniakowski

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by jguinch

Share this post


Link to post
Share on other sites
#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)

:ermm:

Share this post


Link to post
Share on other sites

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)

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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)

:ermm:

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.

Share this post


Link to post
Share on other sites
#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.

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  
Followers 0