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-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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

    • 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
    • Realm
      By Realm
      After Several Minutes searching the forums for a simple solution to calculating for the Unix Time, as required for another project I am working on, I was astonished to not find one clean and universal solution. After looking over the helpfile, I noticed one simple solution given in the example with _DateDiff(). However it did not account for my current timezone or daylight savings time.
      Without further ado... This is my example of Calculating for a current Unix Time stamp or  seconds since Jan, 1st, 1970 00:00:00 GMT.
      This function will account for your timezone as well as for daylight savings time.
      Update: v0.3
      -Added Function to revert a Unix Time stamp into Date form.
      -Added parameter to original _GetUnixTime() allowing for a custom date since Jan 1st 1970 to be passed and converted to Unix Time.
      #include <Date.au3> #include <Array.au3> #include <Constants.au3> Local $iUnixTime1 = _GetUnixTime() MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds Since Jan, 1st, 1970 00:00:00 GMT" & @CRLF & $iUnixTime1) Local $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp in Local Time" & @CRLF & $sUnixDate1) $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1, False) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp with $iReturnLocal = False which returns UTC Time" & @CRLF & $sUnixDate1) Local $iUnixTime2 = _GetUnixTime('2013/01/01 00:00:00') MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds since 2013/01/01 00:00:00" & @CRLF & $iUnixTime2) ; Get timestamp for input datetime (or current datetime). Func _GetUnixTime($sDate = 0);Date Format: 2013/01/01 00:00:00 ~ Year/Mo/Da Hr:Mi:Se Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $utcTime = "" If Not $sDate Then $sDate = _NowCalc() If Int(StringLeft($sDate, 4)) < 1970 Then Return "" If $aSysTimeInfo[0] = 2 Then ; if daylight saving time is active $utcTime = _DateAdd('n', $aSysTimeInfo[1] + $aSysTimeInfo[7], $sDate) ; account for time zone and daylight saving time Else $utcTime = _DateAdd('n', $aSysTimeInfo[1], $sDate) ; account for time zone EndIf Return _DateDiff('s', "1970/01/01 00:00:00", $utcTime) EndFunc ;==>_GetUnixTime ;$blTrim: Year in short format and no seconds. Func _GetDate_fromUnixTime($iUnixTime, $iReturnLocal = True) Local $aRet = 0, $aDate = 0 Local $aMonthNumberAbbrev[13] = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] Local $timeAdj = 0 If Not $iReturnLocal Then Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $timeAdj = $aSysTimeInfo[1] * 60 If $aSysTimeInfo[0] = 2 Then $timeAdj += $aSysTimeInfo[7] * 60 EndIf $aRet = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $iUnixTime + $timeAdj ) If @error Or Not $aRet[0] Then Return "" $aDate = StringSplit(StringTrimRight($aRet[0], 1), " ", 2) Return $aDate[4] & "/" & StringFormat("%.2d", _ArraySearch($aMonthNumberAbbrev, $aDate[1])) & "/" & $aDate[2] & " " & $aDate[3] EndFunc ;==>_GetUnixDate Enjoy!
      Realm
      Update: >Added some functionality and a suggestion from FireFox
    • Simpel
      By Simpel
      Hi, I created a gui with date field but formatted as time in HH:mm. It always shows "now-time". Even if I try to set it with GUICtrlSetData.
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm" ; Just display hours and minutes <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUICtrlSetData($idDate, "00:00") ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example How can I set the time field with another time and how can this field be set blank?
      Regards, Conrad
×