pilotic Posted March 12, 2008 Posted March 12, 2008 I am trying to come up with a macro or script that when run today will return yesterday's date. I currently use the variable of $Day = @Mon & @MDay & @Year which will return for today the values of 03122008. Or if it was run on March 1, 2008 - would return the entry of 03012008. What I need to generate when I run this on March 1, 2008 - is the value related to the prior day. In this case the value returned that I need would have been 02292008. Any guidance or direction is appreciated. NOTE: I am also looking for an easy way to return just the 2 digit year instead of the 4 digit year. Thannks!
James Posted March 12, 2008 Posted March 12, 2008 (edited) For your second problem can you not do: MsgBox(0, "", StringTrimLeft(@YEAR, 2)) Edited March 12, 2008 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
pilotic Posted March 12, 2008 Author Posted March 12, 2008 (edited) For your second problem can you not do: MsgBox(0, "", StringTrimLeft(@YEAR, 2)) Yes - That worked. Thanks! Edited March 12, 2008 by pilotic
weaponx Posted March 12, 2008 Posted March 12, 2008 (edited) #Include <Date.au3> $result = _DateAdd('D', -1, _NowCalcDate()) MsgBox(0,"Yesterday", $result) EDIT: Fixed MsgBox typo. Edited March 12, 2008 by weaponx
rover Posted March 12, 2008 Posted March 12, 2008 (edited) @weaponx typo MsgBox(0,"Yesterday", $result)oÝ÷ ØGb¶·¦¢÷ «^"ÅZ'ç$jëh×6#include<Date.au3> ; _NowCalcDate() Returns the current Date in format YYYY/MM/DD (required for _DateAdd()) $DateSub = _DateAdd('D', -1, _NowCalcDate()) ; subtract 1 day ;The _DateIsValid() is redundant. From the help file for _DateAdd: ;The function will not return an invalid date. ;If _DateIsValid($DateSub) Then ;MsgBox( 4096, "Valid Date", "The specified date is valid." ) ;Else ;MsgBox( 4096, "Valid Date", "The specified date is invalid." ) ;EndIf ; start converting to your format ;-------------------------------------------------- ; this $mdyyyy = StringReplace(_DateTimeFormat($DateSub,2), "/", "") ; Returns the date in the PC's regional settings format MsgBox(0, "", $mdyyyy) ; 03112008 ; or this $aDate = StringSplit($DateSub,"/") If Not IsArray($aDate) Then MsgBox(4096, "Date Format", "Error converting date") Exit EndIf $aDate[1] = StringTrimLeft($aDate[1], 2) $mdyy = $aDate[2] & $aDate[3] & $aDate[1] MsgBox(0, "", $mdyy) ; 031108 ;-------------------------------------------------- Edited March 12, 2008 by rover I see fascists...
weaponx Posted March 12, 2008 Posted March 12, 2008 @rover - The _DateIsValid() is redundant. From the help file for _DateAdd:The function will not return an invalid date.
rover Posted March 12, 2008 Posted March 12, 2008 @rover - The _DateIsValid() is redundant. From the help file for _DateAdd:@weaponxduly noted I see fascists...
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