Sign in to follow this  
Followers 0
pilotic

Returning Yesterday's Date

7 posts in this topic

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!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

For your second problem can you not do:

MsgBox(0, "", StringTrimLeft(@YEAR, 2))
Yes - That worked.

Thanks!

Edited by pilotic

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#Include <Date.au3>
$result = _DateAdd('D', -1, _NowCalcDate())
MsgBox(0,"Yesterday", $result)

EDIT: Fixed MsgBox typo.

Edited by weaponx

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by rover

I see fascists...

Share this post


Link to post
Share on other sites

@rover - The _DateIsValid() is redundant. From the help file for _DateAdd:

The function will not return an invalid date.

Share this post


Link to post
Share on other sites

@rover - The _DateIsValid() is redundant. From the help file for _DateAdd:

@weaponx

duly noted


I see fascists...

Share this post


Link to post
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
Sign in to follow this  
Followers 0