d0n Posted July 30, 2009 Share Posted July 30, 2009 (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 July 30, 2009 by d0n Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted July 30, 2009 Share Posted July 30, 2009 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") .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
d0n Posted July 30, 2009 Author Share Posted July 30, 2009 oo i knew there was one, i just searched Time and didn't find anything lol, thanks for the help Link to comment Share on other sites More sharing options...
d0n Posted July 30, 2009 Author Share Posted July 30, 2009 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] Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 30, 2009 Share Posted July 30, 2009 (edited) Try the _NowCalc UDF, or _Now Edited July 30, 2009 by snowmaker - Bruce /*somdcomputerguy */Â If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
d0n Posted July 30, 2009 Author Share Posted July 30, 2009 This is from a log, so i am not using the current time. Unless i am missing something >_ Link to comment Share on other sites More sharing options...
Malkey Posted July 30, 2009 Share Posted July 30, 2009 (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 July 31, 2009 by Malkey Link to comment Share on other sites More sharing options...
d0n Posted July 30, 2009 Author Share Posted July 30, 2009 thanks will try it out Link to comment Share on other sites More sharing options...
d0n Posted July 31, 2009 Author Share Posted July 31, 2009 (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 July 31, 2009 by d0n 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