Using subtract function with dates

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
adunaway
Newbie
Posts: 11
Joined: Tue Sep 05, 2006 2:05 pm

Using subtract function with dates

Post by adunaway » Fri Oct 06, 2006 8:51 pm

I want to subtract 10 days from the current date.

I execute the following commands:

Day>the_day
Sub>the_day,10

Since today is the 6th, it returns the value -4.

The help file states that Sub can be used with dates or numbers. I would think it is smart enough to recognize the number or days in the month if it can be used for dates.

Am I doing something wrong?

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

Re: Using subtract function with dates

Post by Me_again » Fri Oct 06, 2006 9:04 pm

josh432 wrote:The help file states that Sub can be used with dates or numbers.
It does work with a date:

GetDate>date1
Let>date2=date1
Sub>date2,10
MessageModal>%date1% %date2%

but when you use Day> all you are doing is storing the day number in a variable, that variable doesn't have any connection to the month to know what 10 days before the 6th would be.

There are a bunch of examples on this forum of date arithmetic.

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

Post by Marcus Tettmar » Fri Oct 06, 2006 9:06 pm

Sub can subtract days from dates. So you can do:

Code: Select all

GetDate>the_date
Sub>the_date,10
To return today's date minus 10 days.

But you are just subtracting 10 from the current day number. Day returns the day of the month - which is just a number. So 6 - 10 is -4.
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