
yesterday's date
Moderators: JRL, Dorian (MJT support)
yesterday's date
How could I get yesterday's date (or tomorrow's for that matter)? This seems trivial but somehow I can't seem to arrive to simple solution 

Method one:
GetDate>date
Sub>date,1
Using VBScript:
VBSTART
VBEND
VBEval>date()-1,yesterday
These put the date in the system shortdate format. The following script uses VBScript FormarDateTime function to put the date into longdate format:
VBSTART
VBEND
VBEval>FormatDateTime(date()-1,1),yesterday
There are loads of other ways to do it. You can get the component parts using Year, Month, Day, or strip the parts out of the date returned above using string manipulation, or use VBScript to format it, e.g. here's a line that puts date into YYYY-MM-DD format (regardless of system settings):
VBEval>Year(date()-1)&"-"&Month(date()-1)&"-"&Day(date()-1),yesterday
How about improve this to make a function that takes any date and returns it formatted in this way:
VBSTART
Function DateFormatted(date)
DateFormatted = Year(date) & "-" & Month(date) & "-" & Day(date)
End Function
VBEND
VBEval>DateFormatted(date()-1),yesterday
Hope this helps ...
GetDate>date
Sub>date,1
Using VBScript:
VBSTART
VBEND
VBEval>date()-1,yesterday
These put the date in the system shortdate format. The following script uses VBScript FormarDateTime function to put the date into longdate format:
VBSTART
VBEND
VBEval>FormatDateTime(date()-1,1),yesterday
There are loads of other ways to do it. You can get the component parts using Year, Month, Day, or strip the parts out of the date returned above using string manipulation, or use VBScript to format it, e.g. here's a line that puts date into YYYY-MM-DD format (regardless of system settings):
VBEval>Year(date()-1)&"-"&Month(date()-1)&"-"&Day(date()-1),yesterday
How about improve this to make a function that takes any date and returns it formatted in this way:
VBSTART
Function DateFormatted(date)
DateFormatted = Year(date) & "-" & Month(date) & "-" & Day(date)
End Function
VBEND
VBEval>DateFormatted(date()-1),yesterday
Hope this helps ...
MJT Net Support
[email protected]
[email protected]
For tomorrow's date:
GetDate>date
Add>date,1
Or with VBScript just use date()+1 ... like above but +1, not -1. The number added or subtracted to the date is the number of days to add or subtract.
GetDate>date
Add>date,1
Or with VBScript just use date()+1 ... like above but +1, not -1. The number added or subtracted to the date is the number of days to add or subtract.
MJT Net Support
[email protected]
[email protected]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
We must have written those two last messages at the same time 
Surely I have somewhere better to be on a Friday night!?

Surely I have somewhere better to be on a Friday night!?
MJT Net Support
[email protected]
[email protected]
Because FileDate returns a date in YYYYMMDD format - not a system time format. You can convert it though:
FileDate>c:\test.txt,builddate
MidStr>builddate,1,4,y
MidStr>builddate,5,2,m
MidStr>builddate,7,2,d
VBSTART
VBEND
Let>bdate=%d%-%m%-%y%
VBEval>FormatDateTime("%bdate%"),bdate
Sub>bdate,1
This extracts the year, month and day portions, puts them into a valid date-string and then uses the FormatDateTime to convert to system short date format. Then subtracts 1 from it.
This is one way to do it.
FileDate>c:\test.txt,builddate
MidStr>builddate,1,4,y
MidStr>builddate,5,2,m
MidStr>builddate,7,2,d
VBSTART
VBEND
Let>bdate=%d%-%m%-%y%
VBEval>FormatDateTime("%bdate%"),bdate
Sub>bdate,1
This extracts the year, month and day portions, puts them into a valid date-string and then uses the FormatDateTime to convert to system short date format. Then subtracts 1 from it.
This is one way to do it.
MJT Net Support
[email protected]
[email protected]