Reputation: 1826
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
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