naru Posted March 18, 2019 Share Posted March 18, 2019 I have script to look at todays date from webpage : #include <IE.au3> $oIE = _IEAttach ("Home") Local $date Local $oTds = _IETagNameGetCollection($oIE, "li") For $oTd In $oTds If $oTd.className = "nav navbar-btn" Then $idate = StringSplit($oTd.NextElementSibling.InnerText, " ")[2] ; Because there is a space at beginning it parses that in first spot so we show 2nd ExitLoop EndIf Next MsgBox(0, "date is", $idate) It was Find date like : If it is equal or passes my expiry date then it should exit my script How to make my script stop working after a critain date. i am trying with this : #include <IE.au3> $ExpirationDate = '16/04/2019' $oIE = _IEAttach ("Home") Local $date Local $oTds = _IETagNameGetCollection($oIE, "li") For $oTd In $oTds If $oTd.className = "nav navbar-btn" Then $idate = StringSplit($oTd.NextElementSibling.InnerText, " ")[2] ; Because there is a space at beginning it parses that in first spot so we show 2nd ExitLoop EndIf Next ;~ MsgBox(0, "date is", $idate) If $idate > $ExpirationDate Then MsgBox(64, 'Info:', "your license has ended") But it was not working properly, it only follows the date, not month and Year. If the expired date (only date, not month and year) is smaller than the date it has been received get this msg : "your license has ended". Although there is a big month or year, there is no difference, and the same msg is available. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 18, 2019 Share Posted March 18, 2019 @naru You can't compare two dates like that. Use _DateDiff() to calclulate the difference between the two dates, and use it in your If statement. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
naru Posted March 18, 2019 Author Share Posted March 18, 2019 (edited) 6 minutes ago, FrancescoDiMuro said: @naru You can't compare two dates like that. Use _DateDiff() to calclulate the difference between the two dates, and use it in your If statement. @FrancescoDiMuro I don't know how to use it in my code, the format of date in _datediff is also different then my date. can you help me please Edited March 18, 2019 by naru Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 18, 2019 Share Posted March 18, 2019 (edited) @naru If you click on _DateDiff() in the previous post, there is the Help file linked, related to that function. Just adapt your date format with the one of _DateDiff(), and you're done. One of the many way to format the date for _DateDiff() function: Global $strNewDate = StringRegExpReplace("17/03/2019", '(\d{2}\/(\d{2}\/(\d{4})', '$3/$2/$1') Edited March 18, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
naru Posted March 18, 2019 Author Share Posted March 18, 2019 19 minutes ago, FrancescoDiMuro said: @naru If you click on _DateDiff() in the previous post, there is the Help file linked, related to that function. Just adapt your date format with the one of _DateDiff(), and you're done. One of the many way to format the date for _DateDiff() function: Global $strNewDate = StringRegExpReplace("17/03/2019", '(\d{2}\/(\d{2}\/(\d{4})', '$3/$2/$1') Not converting date, get same date format : Full code is : include <Date.au3> #include <IE.au3> $ExpirationDate = '16/04/2019' $oIE = _IEAttach ("Home") Local $date Local $oTds = _IETagNameGetCollection($oIE, "li") For $oTd In $oTds If $oTd.className = "nav navbar-btn" Then $idate = StringSplit($oTd.NextElementSibling.InnerText, " ")[2] ; Because there is a space at beginning it parses that in first spot so we show 2nd ExitLoop EndIf Next Global $strNewDate = StringRegExpReplace($idate, '(\d{2}\/(\d{2}\/(\d{4})', '$3/$2/$1)') MsgBox(0, "Date", $strNewDate) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 18, 2019 Share Posted March 18, 2019 23 minutes ago, naru said: Not converting date, get same date format : What is your date format like? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
jchd Posted March 18, 2019 Share Posted March 18, 2019 (edited) First, you added a spurious right parenthesis in the replace string. Second, the code doesn't work as it has pattern syntax errors. Try this: Local $strNewDate = StringRegExpReplace("18/03/2019", '(\d{2})\/(\d{2})\/(\d{4})', '$3/$2/$1') MsgBox(0, "Date", $strNewDate) Also note that if you intent to compare dates, for instance using _DateDiff(), then both dates have to use the expected format. $ExpirationDate = '2019/04/16' Edited March 18, 2019 by jchd 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...
FrancescoDiMuro Posted March 18, 2019 Share Posted March 18, 2019 (edited) @jchd Spoiler There is no worse blind as who don't want to see. Edited March 18, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
jchd Posted March 18, 2019 Share Posted March 18, 2019 Oh, I didn't mean to single you out. We're all prone to make this kind of error, especially while typing trivial code like this on the fly. FrancescoDiMuro 1 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...
FrancescoDiMuro Posted March 18, 2019 Share Posted March 18, 2019 @jchd I know that affirmation wasn't for me .The problem is always the same... When someone asks for code, without really understanding what the code does, then posts became 5 pages longer because lazy people keep asking for code, and less lazy people keeps giving them, without letting know what the snippet does. This is what I was meaning Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
naru Posted March 18, 2019 Author Share Posted March 18, 2019 32 minutes ago, jchd said: First, you added a spurious right parenthesis in the replace string. Second, the code doesn't work as it has pattern syntax errors. Try this: Local $strNewDate = StringRegExpReplace("18/03/2019", '(\d{2})\/(\d{2})\/(\d{4})', '$3/$2/$1') MsgBox(0, "Date", $strNewDate) Also note that if you intent to compare dates, for instance using _DateDiff(), then both dates have to use the expected format. $ExpirationDate = '2019/04/16' @jchd Thanks, But i have one more question : is there any different between this two lines : Local $strNewDate = StringRegExpReplace("18/03/2019", '(\d{2})\/(\d{2})\/(\d{4})', '$3/$2/$1') ;~this is your code $inowdate = StringRegExpReplace($idate, "(\d\d)/(\d\d)/(\d\d\d\d)", "$3/$2/$1") ;~i found it from in autoit forum Now my full code is : #include <Date.au3> #include <IE.au3> $endDate = "2018/04/17" $oIE = _IEAttach ("Home") Local $oTds = _IETagNameGetCollection($oIE, "li") For $oTd In $oTds If $oTd.className = "nav navbar-btn" Then $idate = StringSplit($oTd.NextElementSibling.InnerText, " ")[2] ; Because there is a space at beginning it parses that in first spot so we show 2nd ExitLoop EndIf Next $inowdate = StringRegExpReplace($idate, "(\d\d)/(\d\d)/(\d\d\d\d)", "$3/$2/$1") Local $datediff = _DateDiff('D', $inowdate, $endDate) MsgBox($MB_SYSTEMMODAL, "", "Number days this year: " & $datediff) If $datediff > 0 Then MsgBox(0, "Running", "this program running", 15) Exit ElseIf $datediff < 0 Then MsgBox(0, "Expired", "Sorry, this program has expired, contact ....@gmail.com for an extension.", 15) Exit EndIf Link to comment Share on other sites More sharing options...
jchd Posted March 18, 2019 Share Posted March 18, 2019 23 minutes ago, naru said: is there any different between this two lines : No functional difference, just a matter of style (if you don't count CPU cycles down to nanoseconds). FrancescoDiMuro 1 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...
Dionysis Posted March 18, 2019 Share Posted March 18, 2019 (edited) @FrancescoDiMuro @jchd Sorry if it's a bit off-topic, but Why do you escape the forward slash character? Edited March 18, 2019 by Dionysis clarification Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 18, 2019 Share Posted March 18, 2019 (edited) @Dionysis Perl, as many other programming languages, uses the slash "/" as separator between modifiers and the pattern, so it is escaped Edited March 18, 2019 by FrancescoDiMuro Dionysis 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
jchd Posted March 18, 2019 Share Posted March 18, 2019 (edited) Depending on the regex engine, there may be is a value of N above which repetition by <pattern>{N} may sometimes be faster than N explicit repeat <pattern><pattern>...<pattern> Local $d = "123456789 987654321", $s, $t $t = TimerInit() For $i = 1 To 1000000 $s = StringRegExpReplace($d, "(\d{9})\D(\d{9})", "$2 $1") Next ConsoleWrite($s & @TAB & TimerDiff($t) & @LF) $t = TimerInit() For $i = 1 To 1000000 $s = StringRegExpReplace($d, "(\d\d\d\d\d\d\d\d\d)\D(\d\d\d\d\d\d\d\d\d)", "$2 $1") Next ConsoleWrite($s & @TAB & TimerDiff($t) & @LF) Escaping / is pointless, I just copied posted code. Besides, it allows the same string to be used in contexts (engines) where patterns are traditionally delimited by / Edited March 18, 2019 by jchd Dionysis 1 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