Sign in to follow this  
Followers 0
d0n

reading time stamps

9 posts in this topic

#1 ·  Posted (edited)

Right now i am using StringRegExp to read the hour time and second, i was wondering what is the best way to get the time difference of them, is there a function to do this or do i have to use good ol math to determine the difference?

[2:58:24 PM]
[3:05:21 PM]
Edited by d0n

Share this post


Link to post
Share on other sites



I don't think it would be hard to do with a little math, but if you are a bit lazy (who ain't? >_< ) then there is _DateDiff()

(can be found in helpfile under "User Defined Functions>Date Management")

Share this post


Link to post
Share on other sites

oo i knew there was one, i just searched Time and didn't find anything lol, thanks for the help

Share this post


Link to post
Share on other sites

just another quick question regarding time functions, is there a quicker way to obtain the format needed for _DateDiff() than using StringRegExp and doing lots of IF statements for the months and the AM PM

[3:03:24 PM Jul 29 2009]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try the _NowCalc UDF, or _Now

Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

This is from a log, so i am not using the current time. Unless i am missing something >_

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

just another quick question regarding time functions, is there a quicker way to obtain the format needed for _DateDiff() than using StringRegExp and doing lots of IF statements for the months and the AM PM

[3:03:24 PM Jul 29 2009]

Try this.

;
#Include <Date.au3>

Local $sDateTim = "[3:03:24 PM Jul 29 2009]"

Local $sRetVar = StringRegExpReplace($sDateTim, "\[(\d{1,2}):(\d{2}):(\d{2}) (\w{2}) (\w+) (\d{1,2}) (\d{4})\]", _
        '_CallFunction("\1","\2","\3","\4","\5","\6","\7") & ')

$sRetVar = Execute(StringTrimRight($sRetVar, 3))

MsgBox(64, "Results", $sRetVar & @CRLF & _DateDiff("h", $sRetVar, @YEAR & "/" & @MON & "/" &  @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) & " hrs difference")


Func _CallFunction($h, $min, $s, $APm, $mth, $d, $y)
    ConsoleWrite($h & $min & $s & $APm & $mth & $d & $y & @CRLF)
    Local $aMths[13] = [12, "January", "February", "March", "April", "May",  "June", "July", "August", "September", "October", "November", "December"]
    If $APm = "PM" Then
        $h += 12
    EndIf
    For $x = 1 To 12
        If StringInStr($aMths[$x], $mth) <> 0 Then $mth = $x
    Next
    Return StringFormat("%4d/%02d/%02d %02d:%02d:%02d", $y, $mth, $d, $h, $min, $s)
EndFunc   ;==>_CallFunction
;

Edit: Thinking about d0n's post #10, I made the input time/date a lot more flexible in this added script.

;
#include <Date.au3>

Local $sDateTim = "The time/date is 12:3:24 7/29 09."
;Local $sDateTim = "[12:03:24 PM Jul 29 09]"

Local $sRetVar = StringRegExpReplace($sDateTim, ".*?(\d{1,2}):(\d{1,2}):(\d{1,2})\s+(\w{0,2})\s*(\w+|\d{1,2})(\s+|/)(\d{1,2})(\s+|/)(\d{1,4}).*$", _
        '_CallFunction("\1","\2","\3","\4","\5","\7","\9") & ')

$sRetVar = Execute(StringTrimRight($sRetVar, 3))

MsgBox(64, "Results", $sRetVar & @CRLF & _DateDiff("h", $sRetVar, @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) & " hrs difference")


Func _CallFunction($h, $min, $s, $APm, $mth, $d, $y)
    ConsoleWrite($h & $min & $s & $APm & $mth & $d & $y & @CRLF)
    Local $aMths[13] = [12, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
    If StringUpper($APm) = "PM" And $h <> 12 Then
        $h += 12
    EndIf
    If $mth = 0 Then ; if a string then $mth = numeric 0, therefore a month number not used.
        For $x = 1 To 12
            If StringInStr($aMths[$x], $mth) <> 0 Then $mth = $x
        Next
    EndIf
    If StringLen($y) <= 2 Then ; if year only 1 or 2 digits long used then add for correct century.
        If Number($y) > StringRight(@YEAR, 2) Then
            $y = 1900 + Number($y)
        Else
            $y = 2000 + Number($y)
        EndIf
    EndIf
    Return StringFormat("%4d/%02d/%02d %02d:%02d:%02d", $y, $mth, $d, $h, $min, $s)
EndFunc   ;==>_CallFunction
;
Edited by Malkey

Share this post


Link to post
Share on other sites

thanks will try it out

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hey malky your script worked fine until i had a time stamp of [12:10:51 PM Jul 24 2009]

nvm solved it >_<

Edited by d0n

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