Jump to content

Returning Yesterday's Date


Recommended Posts

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!

Link to comment
Share on other sites

@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 by rover

I see fascists...

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...