Zim Posted June 15, 2007 Share Posted June 15, 2007 I am trying to output an excel file for work and I need the excel file to have a standard naming convention (easy one) but at the end, display the last Saturday's date in the following date format. MM-DD-YY (no /, Windows does not allow filenames with /) After reading through the forums, I have found out how to make it output the current date, minus or plus however many days I want to add on, but I can't seem to figure out the logic behind going back to the last Saturday. Here's the script that I have so far. #include <Date.au3> $date = @MON & "-" & @MDAY & "-" & StringRight(@YEAR,2) Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send($date) Any help would be appreciated. I can make Excel output the last saturday's date but am unable to use the same logic in AutoIt and I have been banging my head against this for almost 6 hours. Thanks, Zim Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 15, 2007 Share Posted June 15, 2007 How about: #include <Date.au3> $date = StringReplace(_DateAdd("D", @WDAY * -1, _NowCalcDate()), "/", "-") MsgBox(64, "Results", $date) 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...
Zim Posted June 15, 2007 Author Share Posted June 15, 2007 Thanks! That works GREAT and does what I need it to do, except that eveytime I use the _DateAdd function, it always formats the output in YYYY-MM-DD and I need it to output MM-DD-YY instead. I did receive the correct dates this time so I am happy about that. I was using: $Date = @MON & "-" & @MDAY & "-" & StringRight(@YEAR,2) so I could sort MM, DD and YY accordingly. Do you think I can still do this using _DateAdd? Thanks again, you guys are great!!! Zim Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 15, 2007 Share Posted June 15, 2007 Just use StringSplit() to break up the parts and reassemble them any way you like. Read the help file on StringSplit() and take a shot at it. If it doesn't work, post what you got and you'll get help. 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...
GMK Posted June 15, 2007 Share Posted June 15, 2007 There may be a better way to do this, but this is what I came up with: #include <Date.au3> Dim $Y, $M, $D $today = _DateToDayValue(@YEAR, @MON, @MDAY) $weekday = _DateToDayOfWeek(@YEAR, @MON, @MDAY) Select Case $weekday = 1 $saturday = _DayValueToDate($today - 1, $Y, $M, $D) Case $weekday = 2 $saturday = _DayValueToDate($today - 2, $Y, $M, $D) Case $weekday = 3 $saturday = _DayValueToDate($today - 3, $Y, $M, $D) Case $weekday = 4 $saturday = _DayValueToDate($today - 4, $Y, $M, $D) Case $weekday = 5 $saturday = _DayValueToDate($today - 5, $Y, $M, $D) Case $weekday = 6 $saturday = _DayValueToDate($today - 6, $Y, $M, $D) Case $weekday = 7 $saturday = _DayValueToDate($today - 7, $Y, $M, $D) EndSelect _DayValueToDate($saturday, $Y, $M, $D) $mmddyy = $M & "-" & $D & "-" & StringRight($Y,2) MsgBox(0,"","Last Saturday was: " & $mmddyy) Link to comment Share on other sites More sharing options...
weaponx Posted June 15, 2007 Share Posted June 15, 2007 There may be a better way to do this, but this is what I came up with: #include <Date.au3> Dim $Y, $M, $D $today = _DateToDayValue(@YEAR, @MON, @MDAY) $weekday = _DateToDayOfWeek(@YEAR, @MON, @MDAY) Select Case $weekday = 1 $saturday = _DayValueToDate($today - 1, $Y, $M, $D) Case $weekday = 2 $saturday = _DayValueToDate($today - 2, $Y, $M, $D) Case $weekday = 3 $saturday = _DayValueToDate($today - 3, $Y, $M, $D) Case $weekday = 4 $saturday = _DayValueToDate($today - 4, $Y, $M, $D) Case $weekday = 5 $saturday = _DayValueToDate($today - 5, $Y, $M, $D) Case $weekday = 6 $saturday = _DayValueToDate($today - 6, $Y, $M, $D) Case $weekday = 7 $saturday = _DayValueToDate($today - 7, $Y, $M, $D) EndSelect _DayValueToDate($saturday, $Y, $M, $D) $mmddyy = $M & "-" & $D & "-" & StringRight($Y,2) MsgBox(0,"","Last Saturday was: " & $mmddyy) Wayyyyyyyyyyyyy too much extra code here. Take out the entire Case / EndSelect and just do this: $saturday = _DayValueToDate($today - $weekday, $Y, $M, $D) Link to comment Share on other sites More sharing options...
Zim Posted June 16, 2007 Author Share Posted June 16, 2007 Thanks for everyone's help. I am able to perform the function needed. Zim Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 16, 2007 Moderators Share Posted June 16, 2007 Wayyyyyyyyyyyyy too much extra code here. Take out the entire Case / EndSelect and just do this:$saturday = _DayValueToDate($today - $weekday, $Y, $M, $D)This seems to be one task I wouldn't mind doing manually.... (I'm forced to use the playboy calendar here at the office ) So they all seem like "way" too much code to me Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Valuater Posted June 16, 2007 Share Posted June 16, 2007 This seems to be one task I wouldn't mind doing manually.... (I'm forced to use the playboy calendar here at the office ) So they all seem like "way" too much code to me LMAO8) 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