clockworkninja Posted August 19, 2008 Share Posted August 19, 2008 I'm new to AutoIT, but am pretty knowledgable at scripting in VBS. I would like to retrieve the date of a previous day of the week, in this case, Monday. The following is how to do it in VBS. d = date d= d - (d + 5) mod 7 wscript.echo d I've spent some time trying to figure this out in AutoIT, and can't quite make it happen. I've done an #Include <Date.au3> and have tried to use the _NowCalcDate() and _DateAdd functions to get my results to no avail. Thanks! Link to comment Share on other sites More sharing options...
clockworkninja Posted August 19, 2008 Author Share Posted August 19, 2008 I've tried so many things, I don't know what to post. Here's what I've tried recently. It totally doesn't work because subtracting two dates doesn't work. #Include <Date.au3> $d1 = _NowCalcDate() $d2 = _DateAdd('d',5,$d1) $d3 = mod($d1 - $d2,7) msgbox(0,"test", $d3) I've also tried using _DateDiff('d'$d1,$d2), but that just gives me the difference in days because of the 'd' flag. None of the other flags seem helpful either. Thanks Link to comment Share on other sites More sharing options...
weaponx Posted August 19, 2008 Share Posted August 19, 2008 ;Yesterday _DateAdd('d',-1,$d1) Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 19, 2008 Share Posted August 19, 2008 ;Yesterday _DateAdd('d',-1,$d1) Last week Monday: #include <Date.au3> $iLastMon = _DateToDayOfWeek(@YEAR, @MON, @MDAY) + 5 ConsoleWrite("Last Monday was " & $iLastMon & " days ago." & @LF) $sLastMon = _DateAdd("D", $iLastMon * -1, @YEAR & "/" & @MON & "/" & @MDAY) ConsoleWrite("Last Monday was " & $sLastMon & @LF) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
clockworkninja Posted August 19, 2008 Author Share Posted August 19, 2008 I'd like to be able to programatically figure out what the date of the previous Monday is. So if you ran it on Tuesday, Wednesday, Thursday, etc., it would give you the day of that week's Monday. The VBscript I posted at first does this. I guess I could figure out what day of the week it is, then use a select case, and subtract the correct number of days to give the correct date for Monday. I was just thinking that there would be a way to use the equation that I used in the VBScript to do this in AutoIT (using Mod 7), which would be less code. Thanks, Link to comment Share on other sites More sharing options...
clockworkninja Posted August 19, 2008 Author Share Posted August 19, 2008 (edited) Last week Monday: #include <Date.au3> $iLastMon = _DateToDayOfWeek(@YEAR, @MON, @MDAY) + 5 ConsoleWrite("Last Monday was " & $iLastMon & " days ago." & @LF) $sLastMon = _DateAdd("D", $iLastMon * -1, @YEAR & "/" & @MON & "/" & @MDAY) ConsoleWrite("Last Monday was " & $sLastMon & @LF) Wow, thanks! That works for the previous week, which is what I asked for. I guess I wanted the Monday of the current week though. A slight change to your code (changing +5 to -2) gave me that answer though. I've tested this on the beginning and end of the month, and it works like a champ. It also gives me today's date if that day is Monday, which is exactly what I wanted. Thanks again. CODE#include <Date.au3> $iLastMon = _DateToDayOfWeek(@YEAR, @MON, @MDAY) - 2 ConsoleWrite("Last Monday was " & $iLastMon & " days ago." & @LF) $sLastMon = _DateAdd("D", $iLastMon * -1, @YEAR & "/" & @MON & "/" & @MDAY) ConsoleWrite("Last Monday was " & $sLastMon & @LF) Edited August 19, 2008 by clockworkninja Link to comment Share on other sites More sharing options...
weaponx Posted August 19, 2008 Share Posted August 19, 2008 (edited) CODE REMOVED. Overlooked some things. Edited August 19, 2008 by weaponx 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