Dev
Dev

Reputation: 1826

How to get yesterday's date vbscript

Date format Shows Invalid Date With Custom Date. When I use 'Date' instead of "25th May" it shows yesterday's Date.

function GetYD()
    Dim dt, yesterday

    dt = DateAdd("d", -1, "25th May")

     yesterday = Right(Year(dt),2) & Right("0" & Month(dt),2) & Right("0" & Day(dt),2)
     msgbox yesterday
    GetYD = yesterday
end function

Upvotes: 0

Views: 6817

Answers (1)

Peter B
Peter B

Reputation: 24147

Be sure to feed it a string that can be parsed. Always use digits if possible, and you did not even specify a year.

The format yyyy-mm-dd would probably work best, as it is (both to humans and to computers) totally un-ambiguous. So try it using

DateAdd("d", -1, "2017-05-25")

Upvotes: 2

Related Questions