math on GET DATE

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
marek dydecki
Newbie
Posts: 7
Joined: Sun Jan 25, 2004 12:57 am

math on GET DATE

Post by marek dydecki » Mon Dec 04, 2006 1:47 am

Hi,
I need to rename the file inserting yesterday's date;

'GetDate
Day>the_day
month>the_month
Year>the_year
MidStr>%the_year%,3,4,year
Sub>the_day,1
Let>BSC=d:\local\ACTIVITY.DAT
Let>bct=d:\local\%year%%the_month%%the_day%.bct
MoveFile>BSC,bct

all works fine as long the day is between 11 and 31st
the first ten days of the month return the yy/mm/d while expecting yy/mm/dd

any idea or hint to approach better my problem would be appreciated
thanks
mark

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Dec 04, 2006 2:41 am

Try this. You were going to also have trouble on the first of the month since subtracting one from one would leave you with zero.

Code: Select all

Day>the_day
month>the_month
Year>the_year
Let>today=%the_month%/%the_day%/%the_year%
Sub>today,1
Separate>today,/,var
If>{(%var_1%=1)or(%var_1%=2)or(%var_1%=3)or(%var_1%=4)or(%var_1%=5)or(%var_1%=6)or(%var_1%=7)or(%var_1%=8)or(%var_1%=9)}
Let>var_1=0%var_1%
EndIf
If>{(%var_2%=1)or(%var_2%=2)or(%var_2%=3)or(%var_2%=4)or(%var_2%=5)or(%var_2%=6)or(%var_2%=7)or(%var_2%=8)or(%var_2%=9)}
Let>var_2=0%var_2%
EndIf
midstr>var_3,3,2,var_3
Let>BSC=d:\local\ACTIVITY.DAT
Let>bct=d:\local\%var_3%%var_1%%var_2%.bct
MoveFile>BSC,bct

marek dydecki
Newbie
Posts: 7
Joined: Sun Jan 25, 2004 12:57 am

math on GET DATE

Post by marek dydecki » Mon Dec 04, 2006 3:22 am

Hi,
thanks for the code. I do not think I understand the SEPARATE function and I am not sure if I adjusting your code as below would work for me

in your example the date string is
%the_month%/%the_day%/%the_year%

and the final line is
%var_3%%var_1%%var_2%

the date string I need
%year%%the_month%%the_day%

should my final line read
%var_2%%var_3%%var_1%
thanks

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Dec 04, 2006 3:44 am

Lots of info on getting yesterday's date here http://www.mjtnet.com/usergroup/viewtop ... =yesterday

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Mon Dec 04, 2006 4:33 am

if the link from Me_Again covers this, forgive me, but here is the easiest way to get the date in the format you want.

control panel, regional settings, the customize button by your current location, then the date tab. Select the format of MM/DD/YYYY

then use

vbstart
vbend
vbe>Date()-1,mydate


now mydate will contain MM/DD/YYYY

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Dec 04, 2006 8:34 am

No need to mess about with regional settings. This is my solution:

Code: Select all

VBSTART
VBEND
VBEval>Year(Date()-1) & Right("0" & Month(Date()-1),2) & Right("0" & Day(Date()-1),2),yDateString
Last edited by Marcus Tettmar on Mon Dec 04, 2006 6:26 pm, edited 1 time in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Dec 04, 2006 6:20 pm

This worked great after I removed the extra VBEval> (there were two in the code above as originally posted):
mtettmar wrote:VBSTART
VBEND
VBEval>VBEval>Year(Date()-1) & Right("0" & Month(Date()-1),2) & Right("0" & Day(Date()-1),2),yDateString
Nice little piece of code, thanks Marcus... added to snipets. :)
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Dec 04, 2006 6:26 pm

Oops. Have edited my post and removed the erroneous extra VBEval.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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