yesterday's date

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
vanfanel
Newbie
Posts: 15
Joined: Sat Sep 11, 2004 12:38 pm

yesterday's date

Post by vanfanel » Fri Oct 08, 2004 7:37 pm

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 :?

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Oct 08, 2004 7:51 pm

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 ...
MJT Net Support
[email protected]

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Oct 08, 2004 7:53 pm

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.
MJT Net Support
[email protected]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Oct 08, 2004 7:54 pm

Tomorrow's date:
GetDate>Now
Add>Now,1
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Oct 08, 2004 7:55 pm

We must have written those two last messages at the same time ;-)

Surely I have somewhere better to be on a Friday night!?
MJT Net Support
[email protected]

vanfanel
Newbie
Posts: 15
Joined: Sat Sep 11, 2004 12:38 pm

Post by vanfanel » Fri Oct 08, 2004 8:14 pm

thanks! Why doesn't this work for FileDate though? That seems to be treated as a number

FileDate>c:\test.txt,builddate
Sub>builddate,8
Message>builddate

that returns:
20040999

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Oct 08, 2004 9:27 pm

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.
MJT Net Support
[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts