DarkestHour Posted April 18, 2011 Share Posted April 18, 2011 I just have a (hopefully) quick question. How would i go about forcing Autoit to recognize the number 1 as 01, 2 as 02 and so forth. I currently have a script that is pulling from a database for time's, modifying it and then searching for records in a timeframe. For example here is the code where i would need it. The problem being that when i subtract 5 from 10 i get 5 not 05. I could always modify the numbers before hand then Concatenate the 0 in front if it's from 0 to 9. But i hope there was a much simpler way. $TIMEtemp = $DBFr.GetRows() ; Returns data from sql command into 2d array $time = StringSplit($Timetemp[0][0], ":") ; Take 12:34:56 and splits it into an array. $TimeBef = $time[1] &":"& $time[2] &":"& ($time[3] - 5) ; Modifies the first time to 5 seconds before $TimeAft = $time[1] &":"& $time[2] &":"& ($time[3] + 5) ; Modifies the first time to 5 seconds after $timetemp[0][1] = StringTrimRight($TIMETEMP[0][1], 6) ; This is removing the excess numbers from the date field $timetemp[0][1] = _StringInsert($timetemp[0][1], "/", 4) ; The following 4 lines reformat it to a proper date $timetemp[0][1] = _StringInsert($timetemp[0][1], "/", 7) $TEMPS = _StringExplode($timetemp[0][1], "/") $timetemp[0][1] = $TEMPS[1]&"/"&$TEMPS[2]&"/"&$TEMPS[0] Ahh yes, and also looking at the code i allow it to go into the negatives instead of looping back. i can fix that fairly easily. Thanks for any help! -Kevin Link to comment Share on other sites More sharing options...
enaiman Posted April 18, 2011 Share Posted April 18, 2011 StringFormat is your friend here - here is a simple example: $number = 5 MsgBox(0, "", StringFormat("%02d", $number)) SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
jchd Posted April 19, 2011 Share Posted April 19, 2011 Maybe it would be much easier and faster to add your conditions in a WHERE clause of the SELECT query to retrieve only the rows of interest. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
DarkestHour Posted April 19, 2011 Author Share Posted April 19, 2011 Maybe it would be much easier and faster to add your conditions in a WHERE clause of the SELECT query to retrieve only the rows of interest.I am going to use enaiman's solution here.This is needed FOR the where clause in the sql statement. The SQL Statements for my time fields don't count 12:12:1 and 12:12:01 as the same thing, thus failing to pull any data in between my two times.Thanks!-Kevin Link to comment Share on other sites More sharing options...
jchd Posted April 19, 2011 Share Posted April 19, 2011 Then the actual root cause is the wrong formatting of the dates at INSERT/UPDATE time. If you own the DB and can manage it then it would be convenient to update date/times already stored into ISO format (or integer timestamp format or anything reliable) to make the whole issue disappear forever. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
DarkestHour Posted April 19, 2011 Author Share Posted April 19, 2011 Then the actual root cause is the wrong formatting of the dates at INSERT/UPDATE time.If you own the DB and can manage it then it would be convenient to update date/times already stored into ISO format (or integer timestamp format or anything reliable) to make the whole issue disappear forever.Agree'd, while we do own the database we do not have the source code for the software that also interfaces with it. So i have to manage the time in this way the pull the data.-Kevin Link to comment Share on other sites More sharing options...
jchd Posted April 19, 2011 Share Posted April 19, 2011 It's a pity! Good luck anyway. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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