Diana (Cda) Posted June 15, 2009 Share Posted June 15, 2009 (edited) Some time back I was kindly given this specialized date format that I use constantly, i.e., in backup names to show date. It decreases the standard 3-character short date format to just 2 characters:$ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2)oÝ÷ ØÊøvÚ,¹»kiËhçZÉ«¢+ØÀÌØíM¡½ÉÑå5å½ÉµÐôMÑÉ¥¹5¥ ÅÕ½ÐíM¸±5¸±QÔ±]±Q ±È±MÅÕ½Ðì°MÑÉ¥¹%¹MÑÈ ÅÕ½ÐíMÕ¹5½¹QÕ]Q¡ÕÉ¥MÐÅÕ½Ðì°}Ñå=]¬¡]d´Ä°Ä¤¤°ÈFor some reason, though "-1" above with @WDAY (and @MDAY elsewhere in script) gives me yesterday's date in both day of month and day of week, anything beyond that becomes unreliable ... i.e., when I try using "-2", "-3" and beyond. So even though 0 for today and -1 for yesterday works, this technique must actually not be the correct way since anything beyond that gives some pretty wacky results sometimes. Is there a way to get dates based on a starting date and subtracting from it?? Edited June 15, 2009 by Diana (Cda) Link to comment Share on other sites More sharing options...
water Posted June 15, 2009 Share Posted June 15, 2009 With _DateAdd you can subtract as well. See example 2 in the helpfile. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Malkey Posted June 15, 2009 Share Posted June 15, 2009 Some time back I was kindly given this specialized date format that I use constantly, i.e., in backup names to show date. It decreases the standard 3-character short date format to just 2 characters: $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2) Modified to subtract one day: $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY-1,1) ), 2) For some reason, though "-1" above with @WDAY (and @MDAY elsewhere in script) gives me yesterday's date in both day of month and day of week, anything beyond that becomes unreliable ... i.e., when I try using "-2", "-3" and beyond. So even though 0 for today and -1 for yesterday works, this technique must actually not be the correct way since anything beyond that gives some pretty wacky results sometimes. Is there a way to get dates based on a starting date and subtracting from it?? Using Mod() in _DateDayOfWeek() will produce a zero which is not allowed as a parameter. "One" must be added after the Mod() to avoid zero. To keep today's day of the week correct, "minus one" is added within the Mod() function. ; #include <Date.au3> Local $sRes = "" For $x = -11 To 9 $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", _ StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(Mod(49 + @WDAY + $x, 7) + 1, 1)), 2) $sRes &= $x + 1 & " days from today = " & $ShortDayMyFormat & @CRLF Next $sRes &= @CRLF & "Today is = " & StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", _ StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(Mod(49 + @WDAY - 1, 7) + 1, 1)), 2) MsgBox(0, "", $sRes) ; 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