Hey, Scripting Guy! I’m writing a script, and I need to know yesterday’s date. I can use Date() to figure out today’s date, but how do I figure out yesterday’s date?
Hey, SS. You’re right; it’s easy to determine today’s date using a script:
dtmToday = Date()
But what about yesterday’s date? Listen, we’ve got good news for you: it’s just as easy to determine yesterday’s date as it is today’s date. That’s because VBScript can do date arithmetic: give it today’s date, and then you can simply subtract 1 day to determine yesterday’s date. In other words:
dtmYesterday = Date() - 1
Want to know tomorrow’s date? You’re way ahead of us:
dtmTomorrow = Date() + 1
Cool, huh? Incidentally, you can do even fancier date arithmetic using VBScript. Want to know the date that’s 37 days from July 30, 2004? You can calculate that using the DateAdd function:
dtmDate = DateAdd("d", 37, "July 30, 2004")
For more information about the DateAdd function, see this portion of the Microsoft Windows 2000 Scripting Guide.