Jump to content
Sign in to follow this  
damon

Get the time difference from 2 times

Recommended Posts

damon

I am trying to take 2 times and determine the difference,

example:

Time one

13:43:24,424

Time two

13:44:35:424

Time that has passed is 0:1:11,000

how can i get the time that has passed?

 


It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites
water

Something like this:

#include <date.au3>
Global $sTime1 = "13:43:24", $sTime2 = "13:44:35"
Global $iTime1,  $iTime2
Global $aTemp, $sHour, $sMinute, $sSecond
$aTemp = StringSplit($sTime1, ":")
$iTime1 = _TimeToTicks($aTemp[1], $aTemp[2], $aTemp[3])
$aTemp = StringSplit($sTime2, ":")
$iTime2 = _TimeToTicks($aTemp[1], $aTemp[2], $aTemp[3])
_TicksToTime($iTime2-$iTime1, $sHour, $sMinute, $sSecond)
ConsoleWrite($sHour & ":" & $sMinute & ":" & $sSecond & @LF)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
BrewManNH

 

Something like this:

That's almost the exact same code I came up with. :D Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
water

What's missing is some code to strip off the milliseconds from the input values. I will leave this to the OP ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
iamtheky

How would you do this for something that runs over midnight?


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
water

Then you would need to pass date AND time and use _DateDiff to calculate the difference.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
damon

just tested in my script, thats exactly what i was looking for.  I was playing with _TicksToTime but i was not using it correctly.  thank you


It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites
iamtheky

Does the provided solution offer any benefits over:

$Start = "13:43:24:424"
$aStart = stringsplit($Start , ":")


$End = "13:44:21:300"
$aEnd = stringsplit($End , ":")


$Hour = $aEnd[1] - $aStart[1]
$Min = $aEnd[2] - $aStart[2]
$Sec = $aEnd[3] - $aStart[3]
$Ms = $aEnd[4] - $aStart[4]


If $Ms < 0 Then
$Sec -= 1
$Ms = 1000 + $Ms
Endif


If $Sec < 0 Then
$Min -= 1
$Sec = 60 + $Sec
Endif


If $Min < 0 Then
$Hour -= 1
$Min = 60 + $Min
Endif


msgbox(0, '' , $Hour & ":" & $Min & ":" & $Sec & ":" & $Ms)
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
water

If the result if the same I don't see a difference.

Both scripts should be tested if they return proper results when run over midnight.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
damon

I know i showed millisecs in the original post but I did not have to add it, so the first was great, i am rewriting it to better fit my script but that was exactly what i was trying to do.

 

thanks to all,


It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites
damon

oh, wow.  Water, i just caught on to what you were saying and tested it.  when it runs past the 24 hr mark it returns 12:1:11

so if i had a 23 hr time and 1hr comparison it will show something like 22 hrs difference instead of 1 - 2 hrs

Edited by damon

It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites
water

To properly compare time values past the 24 hr mark you need to pass the date as well and use _DateDiff.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
damon

ok, i can do that.  its a server log file so i have that information.


It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites
iamtheky

What is the best practice for  "If <this>" or "If <this and that>" or " If <this and that and that>" if they all result in the same action, without copying the same stuff throughout the script (as that was the easiest solution)?

This one accounts for a single 24 hour period, with midnight rollover.

;;;;;; input

$Start = "22:43:24:424"

$End = "20:49:49:100"

;;;;;; end input

$aStart = stringsplit($Start , ":")
$aEnd = stringsplit($End , ":")

$Midnight = "23:59:59:999"
$aMidnight = stringsplit($Midnight , ":")

If $aEnd[1] < $aStart[1] Then
    $HourStart = $aMidnight[1] - $aStart[1]
    $MinStart = $aMidnight[2] - $aStart[2]
    $SecStart = $aMidnight[3] - $aStart[3]
    $MsStart = $aMidnight[4] - $aStart[4]
    $elapsedDay1 = _CheckTime($HourStart , $MinStart , $SecStart , $MsStart)

    $HourEnd = 0 + number($aEnd[1])
    $MinEnd = 0 + number($aEnd[2])
    $SecEnd = 0 + number($aEnd[3])
    $MsEnd = 0 + number($aEnd[4])
    $elapsedDay2 = _CheckTime($HourEnd , $MinEnd , $SecEnd , $MsEnd)

    $aDay1 = stringsplit($elapsedDay1 , ":")
    $aDay2 = stringsplit($elapsedDay2 , ":")

    $Hour = $aDay1[1] + $aDay2[1]
    $Min = $aDay1[2] + $aDay2[2]
    $Sec = $aDay1[3] + $aDay2[3]
    $Ms = $aDay1[4] + $aDay2[4]

ElseIf $aEnd[1] = $aStart[1] and $aEnd[2] < $aStart[2] Then
    $HourStart = $aMidnight[1] - $aStart[1]
    $MinStart = $aMidnight[2] - $aStart[2]
    $SecStart = $aMidnight[3] - $aStart[3]
    $MsStart = $aMidnight[4] - $aStart[4]
    $elapsedDay1 = _CheckTime($HourStart , $MinStart , $SecStart , $MsStart)

    $HourEnd = 0 + number($aEnd[1])
    $MinEnd = 0 + number($aEnd[2])
    $SecEnd = 0 + number($aEnd[3])
    $MsEnd = 0 + number($aEnd[4])
    $elapsedDay2 = _CheckTime($HourEnd , $MinEnd , $SecEnd , $MsEnd)

    $aDay1 = stringsplit($elapsedDay1 , ":")
    $aDay2 = stringsplit($elapsedDay2 , ":")

    $Hour = $aDay1[1] + $aDay2[1]
    $Min = $aDay1[2] + $aDay2[2]
    $Sec = $aDay1[3] + $aDay2[3]
    $Ms = $aDay1[4] + $aDay2[4]

ElseIf $aEnd[1] = $aStart[1] and $aEnd[2] = $aStart[2] and $aEnd[3] < $aStart[3] Then
    $HourStart = $aMidnight[1] - $aStart[1]
    $MinStart = $aMidnight[2] - $aStart[2]
    $SecStart = $aMidnight[3] - $aStart[3]
    $MsStart = $aMidnight[4] - $aStart[4]
    $elapsedDay1 = _CheckTime($HourStart , $MinStart , $SecStart , $MsStart)

    $HourEnd = 0 + number($aEnd[1])
    $MinEnd = 0 + number($aEnd[2])
    $SecEnd = 0 + number($aEnd[3])
    $MsEnd = 0 + number($aEnd[4])
    $elapsedDay2 = _CheckTime($HourEnd , $MinEnd , $SecEnd , $MsEnd)

    $aDay1 = stringsplit($elapsedDay1 , ":")
    $aDay2 = stringsplit($elapsedDay2 , ":")

    $Hour = $aDay1[1] + $aDay2[1]
    $Min = $aDay1[2] + $aDay2[2]
    $Sec = $aDay1[3] + $aDay2[3]
    $Ms = $aDay1[4] + $aDay2[4]

ElseIf $aEnd[1] = $aStart[1] and $aEnd[2] = $aStart[2] and $aEnd[3] = $aStart[3] and $aEnd[4] < $aStart[4] Then
    $HourStart = $aMidnight[1] - $aStart[1]
    $MinStart = $aMidnight[2] - $aStart[2]
    $SecStart = $aMidnight[3] - $aStart[3]
    $MsStart = $aMidnight[4] - $aStart[4]
    $elapsedDay1 = _CheckTime($HourStart , $MinStart , $SecStart , $MsStart)

    $HourEnd = 0 + number($aEnd[1])
    $MinEnd = 0 + number($aEnd[2])
    $SecEnd = 0 + number($aEnd[3])
    $MsEnd = 0 + number($aEnd[4])
    $elapsedDay2 = _CheckTime($HourEnd , $MinEnd , $SecEnd , $MsEnd)

    $aDay1 = stringsplit($elapsedDay1 , ":")
    $aDay2 = stringsplit($elapsedDay2 , ":")

    $Hour = $aDay1[1] + $aDay2[1]
    $Min = $aDay1[2] + $aDay2[2]
    $Sec = $aDay1[3] + $aDay2[3]
    $Ms = $aDay1[4] + $aDay2[4]


Else

    $Hour = $aEnd[1] - $aStart[1]
    $Min = $aEnd[2] - $aStart[2]
    $Sec = $aEnd[3] - $aStart[3]
    $Ms = $aEnd[4] - $aStart[4]

Endif


$Diff = _CheckTime($Hour , $Min, $Sec , $Ms)
$aDiff = stringsplit($Diff , ":")

    for $i = 1 to 4
        if StringLen($aDiff[$i]) < 2 Then $aDiff[$i] = "0" & $aDiff[$i]
    Next

msgbox(0, '' , $aDiff[1] & ":" & $aDiff[2] & ":" & $aDiff[3] & ":" & $aDiff[4])


Func _CheckTime($Hour , $Min , $Sec , $Ms)

If $Ms < 0 Then
    $Sec -= 1
    $Ms = 1000 + $Ms
ElseIf $Ms > 999 Then
    $Sec += 1
    $Ms = $Ms - 1000
Endif

If $Sec < 0 Then
    $Min -= 1
    $Sec = 60 + $Sec
ElseIf $Sec > 59 Then
    $Min += 1
    $Sec = $Sec - 60
Endif

If $Min < 0 Then
    $Hour -= 1
    $Min = 60 + $Min
ElseIf $Min > 59 Then
    $Hour += 1
    $Min = $Min - 60
Endif

return $Hour & ":" & $Min & ":" & $Sec & ":" & $Ms

EndFunc

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
water

Modified my script to handle 24 hrs rollover as well:

#include <date.au3>
Global $sTime1 = "13:43:24", $sTime2 = "13:44:35"
Global $iTime1, $iTime2, $iTime24
Global $aTemp, $sHour, $sMinute, $sSecond
$aTemp = StringSplit($sTime1, ":")
$iTime1 = _TimeToTicks($aTemp[1], $aTemp[2], $aTemp[3])
$aTemp = StringSplit($sTime2, ":")
$iTime2 = _TimeToTicks($aTemp[1], $aTemp[2], $aTemp[3])
_TicksToTime($iTime2 - $iTime1, $sHour, $sMinute, $sSecond)
If Number(StringReplace($sTime1, ":", "")) < Number(StringReplace($sTime2, ":", "")) Then
    _TicksToTime($iTime2 - $iTime1, $sHour, $sMinute, $sSecond) ; No 24 hr rollover
Else
    $iTime24 = _TimeToTicks("24", "00", "00") ; 24 hr rollover
    _TicksToTime($iTime2 + $iTime24 - $iTime1, $sHour, $sMinute, $sSecond)
EndIf
ConsoleWrite(StringRight("0" & $sHour, 2) & ":" & StringRight("0" & $sMinute, 2) & ":" & StringRight("0" & $sSecond, 2) & @LF)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
AZJIO

'?do=embed' frameborder='0' data-embedContent>>

#include <_DateDiff_2.au3>
#include <Array.au3>

Local $Old[6] = [2013, 08, 23, 13, 43, 24.240]
Local $New[6] = [2013, 08, 23, 13, 44, 35.925]
; Local $New[6] = [2013, 08, 23, 13, 43, 24.240]
; Local $Old[6] = [2013, 08, 23, 13, 44, 35.925]

$aAge = _DateDiff_2($Old, $New)
$s = '+'
If @extended Then $s = '-'
$s &= $aAge[0] & '/' & $aAge[1] & '/' & $aAge[2] & '  ' & $aAge[3] & ':' & $aAge[4] & ':' & $aAge[5] 
_ArrayDisplay($aAge, $s)
Edited by AZJIO
  • Like 1

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  

  • Similar Content

    • Jemboy
      By Jemboy
      Hi,
      Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier.
      I have to upload the file to an FTP to get it processed.
      When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded.
      Normally this is fine, because I mostly upload the file the same day.
      Sometimes it may take 1 or 2 days before I can upload the file.
      For historical purpose, I would like to have the file timestamped with the original date.
      I have tried using:  _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") 
      however this command does not work or change the timestamp as I expected.
      Does anyone now a way how I can change the timestamp of a FTP-file?
    • Rskm
      By Rskm
      Hi, for a script of mine, I wish to keep a time frame on till how the program will work.. basically, I want the program to read the date and if the read date < 'a particular date', the program continues, else it exit. I don't want to read the time from the computer as the program can be fooled by resetting the pc time. is there a way to read time from internet - so that the user cannot fool the program by date reset? thanks
    • Shedunn
      By Shedunn
      I've been looking through some different functions(not sure if that's the right word) to get the Date and time and I can't find one that doesn't include "/ " or ":" in what is returned.

      I'm trying to create a file name with this format "QuickConfig_MMDDYYYY_HHMM"  (doesn't matter if 24 or 12hr format)
      #include <Date.au3> Func _SaveConfig MouseClick('primary',155, 46, 1, 0) ;clicks save as WinWait('Save bluePRINT Configuration As...','', 4) MouseClick('primary',632, 47, 1, 0) ;clicks the file path bar $Documents = @MyDocumentsDir $FilePath = $Documents & '\BP3 Configs' Send($FilePath) Send('{ENTER}') MouseClick('primary',166, 580, 1, 0) ;clicks file name bar $FileName = 'QuickConfig_' & _NowDate & '_' & _NowTime Send($FileName) Send('{ENTER}') EndFunc  
       
      I'm wondering if there is a function somewhere to do this?
    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • imitto
      By imitto
      Hello all!
      I use Autoit for a while, already made some automation for a TV station's master control room with it. I made a UDF to easily work with PAL timecode and time with milliseconds, convert, add or subtract them. Feel free to use it if you want something like this
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Description=PAL Timecode Calculator UDF #AutoIt3Wrapper_Res_LegalCopyright=horvath.imre@gmail.com #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; ; #FUNCTION# ; Name...........: _tcAdd ; Description....: Returns addition of two timecodes ; Syntax.........: _tcAdd($fTc1, fTc2 [, $fFormat = "P"]) ; ; Parameters.....: $fTc1 - First timecode in hh:mm:ss.ff format ; $fTc2 - Second timecode in hh:mm:ss.ff format ; $fFormat - Time base - "P" (default): PAL (25 fps) ; "M" : millisecond ; ; Return value...: Sum of the two timecode in the selected format Func _tcAdd($fTc1, $fTc2, $fFormat = "P", $fHourFormat = 1) Local $fMs1 = _tcToMs($fTc1) Local $fMs2 = _tcToMs($fTc2) Local $fSumMs = $fMs1 + $fMs2 Return _msToTc($fSumMs, $fFormat, $fHourFormat) EndFunc ; #FUNCTION# ; Name...........: _tcsSub ; Description....: Returns addition of two timecodes ; Syntax.........: _tcSub($fTc1, fTc2 [, $fFormat = "P"]) ; ; Parameters.....: $fTc1 - First timecode in hh:mm:ss.ff format ; $fTc2 - Second timecode in hh:mm:ss.ff format ; $fFormat - Time base - "P" (default): PAL (25 fps) ; "M" : millisecond ; ; Return value...: Subtract $fTc2 from $fTc1 in the source format Func _tcSub($fTc1, $fTc2, $fFormat = "P") Local $fMs1 = _tcToMs($fTc1) Local $fMs2 = _tcToMs($fTc2) Local $fSumMs = $fMs1 - $fMs2 If $fSumMs < 0 Then $fSumMs = _tcToMs("24:00:00.00") - ($fSumMs * -1) EndIf Return _msToTc($fSumMs, $fFormat) EndFunc ; #FUNCTION# ; Name...........: _tcToMs ; Description....: Returns timecode converted to total milliseconds ; Syntax.........: _tcToMs($fTc) ; ; Parameters.....: $fTc - Timecode in hh:mm:ss.ff or hh:mm:ss:xxx format, where xxx are milliseconds ; ; Return value...: Milliseconds as an integer value Func _tcToMs($fTc) Local $fTemp = StringSplit($fTc, ":.") Local $fChr = StringLen($fTemp[4]) Switch $fChr Case 2 Return ($fTemp[4] * 40) + ($fTemp[3] * 1000) + ($fTemp[2] * 60000) + ($fTemp[1] * 3600000) Case 3 Return ($fTemp[4]) + ($fTemp[3] * 1000) + ($fTemp[2] * 60000) + ($fTemp[1] * 3600000) EndSwitch EndFunc ; #FUNCTION# ; Name...........: _msToTc ; Description....: Converts total milliseconds to timecode ; Syntax.........: _msToTc($fIn, $fFormat = "P", $fHourFormat = 1) ; ; Parameters.....: $fIn - Time in milliseconds ; $fFormat - Output format "P": PAL TC (default) ; "M": hh:mm:ss.xxx where xxx are milliseconds ; $fHourFormat - Hour format "1": max. value is 23, then starts from 0 (default) ; "0": hours can be more then 23 ; ; Return value...: Timecode as string in the selected format Func _msToTc($fIn, $fFormat = "P", $fHourFormat = 1) Switch $fFormat Case "P" Local $fFr = StringFormat("%02i", (StringRight($fIn, 3) - Mod(StringRight($fIn, 3), 40)) / 40) Case "M" Local $fFr = StringFormat("%03i", StringRight($fIn, 3)) EndSwitch $fIn = StringTrimRight($fIn, 3) Local $fSec = StringFormat("%02i", Mod($fIn, 60)) $fIn -= $fSec Local $fMinTot = $fIn / 60 Local $fMin = StringFormat("%02i", Mod($fMinTot, 60)) $fIn -= $fMin*60 Local $fHourTot = $fIn / 60 / 60 Switch $fHourFormat Case 1 $fHour = StringFormat("%02i", Mod($fHourTot, 24)) Case 0 $fHour = StringFormat("%02i", $fHourTot) EndSwitch Return($fHour & ":" & $fMin & ":" & $fSec & "." & $fFr) EndFunc ; #FUNCTION# ; Name...........: _tcFormatChange ; Description....: Toggle TC format ; Syntax.........: _tcFormatChange($fTc) ; ; Parameters.....: $fTc - Timecode in hh:mm:ss.ff or hh:mm:ss:xxx format, where xxx are milliseconds ; ; Return value...: PAL timecode or time with milliseconds as string, depends on input Func _tcFormatChange($fTc) Local $fTemp = StringSplit($fTc, ":.") Local $fChr = StringLen($fTemp[4]) Switch $fChr Case 2 Return $fTemp[1]&":"&$fTemp[2]&":"&$fTemp[3]&"."&StringFormat("%03i", $fTemp[4]*40) Case 3 Return $fTemp[1]&":"&$fTemp[2]&":"&$fTemp[3]&"."&StringFormat("%02i", ($fTemp[4]-Mod($fTemp[4], 40))/40) EndSwitch EndFunc And the example script:
      #include<_PAL_TC_Calc.au3> $palTC1 = "00:01:12.20" $palTC2 = "23:59:50.02" $msTC1 = "00:01:12.800" $msTC2 = "23:59:50.120" MsgBox(0, "1", _tcAdd($palTC1, $palTC2)); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns PAL TC format MsgBox(0, "2", _tcAdd($palTC1, $palTC2, "M")); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns time with milliseconds format MsgBox(0, "3", _tcAdd($palTC1, $palTC2, "M", 0)); Adds $palTC1 to $palTC2, hours can be infinite, returns time with milliseconds format MsgBox(0, "4", _tcAdd($msTC1, $msTC2)); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns PAL TC format MsgBox(0, "5", _tcAdd($msTC1, $msTC2, "M")); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns time with milliseconds format MsgBox(0, "6", _tcAdd($msTC1, $msTC2, "M", 0)); Adds $palTC1 to $palTC2, hours can be infinite, returns time with milliseconds format MsgBox(0, "7", _tcSub($palTC2, $palTC1)); Subtract $palTC1 from $palTC2, returns PAL TC format MsgBox(0, "8", _tcSub($palTC2, $palTC1, "M")); Subtract $palTC1 from $palTC2, time with milliseconds format MsgBox(0, "9", _tcSub($msTC1, $msTC2)); Subtract $palTC1 from $palTC2, returns PAL TC format - when hits zero, counts back from 24:00:00.00 MsgBox(0, "10", _tcSub($msTC1, $msTC2, "M")); Subtract $palTC1 from $palTC2, time with milliseconds format - when hits zero, counts back from 24:00:00.000 MsgBox(0, "11", _tcFormatChange($palTC2)); Convert PAL TC to time with milliseconds and back MsgBox(0, "12", _tcFormatChange($msTC2)); Convert PAL TC to time with milliseconds and back  
      TC_CALC_example.au3
      _PAL_TC_Calc.au3
×