Yesterday date

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Yesterday date

Post by Identis » Fri Mar 17, 2023 7:28 am

Hello,
I have 12version, is it possible to get yesterday date ?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1378
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Yesterday date

Post by Dorian (MJT support) » Fri Mar 17, 2023 9:22 am

Sadly v12 was released 13 years ago so is out of support.

The usual way of doing this would be :

Code: Select all

GetDate>today
DateAdd>today,D,-1,yesterday
But unfortunately DateAdd was only added in v13, 12 years ago.

GetDate was in v12 though, so that would at least be a starting point.
Yes, we have a Custom Scripting Service. Message me or go here

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

Re: Yesterday date

Post by JRL » Fri Mar 17, 2023 1:54 pm

This should work in version 4 onward.

Code: Select all

//Pure Macro Scheduler
Month>mm
Day>dd
Year>yyyy

Let>today=%mm%/%dd%/%yyyy%
Sub>today,1
//Variable today is now yesterday's date.
MDL>today

//Or VBScript
VBStart
VBEnd

VBEval>now-1,yesterday
MDL>yesterday
//The result is date and time
//To have only the date
Separate>yesterday,space,vNow

MDL>vNow_1

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1378
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Yesterday date

Post by Dorian (MJT support) » Fri Mar 17, 2023 2:14 pm

JRL wrote:
Fri Mar 17, 2023 1:54 pm
This should work in version 4 onward.

Code: Select all

//Pure Macro Scheduler
Month>mm
Day>dd
Year>yyyy

Let>today=%mm%/%dd%/%yyyy%
Sub>today,1
//Variable today is now yesterday's date.
MDL>today

//Or VBScript
VBStart
VBEnd

VBEval>now-1,yesterday
MDL>yesterday
//The result is date and time
//To have only the date
Separate>yesterday,space,vNow

MDL>vNow_1
Thank you for that. I'm quite amazed that Sub>today,1 detected the date correctly like that.

Seeing as GetDate was also in v12, this should also work :

Code: Select all

GetDate>today
Sub>today,1
Yes, we have a Custom Scripting Service. Message me or go here

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

Re: Yesterday date

Post by JRL » Fri Mar 17, 2023 6:05 pm

I don't want to change my regional date setting to test but as I recall GetDate> presents in the format specified in regional settings. For Add> and Sub> to work with a date the date has to be in month/day/year format. No other format will work. You can use 1 digit month and day as well as 2 digit year, but the date has to be month/day/year. Another caveat if you use 2 digit year is that you can get the wrong century. 72 and smaller will give you a 20xx result but 73 though 99 will provide a 19xx result. No issues at all if you use a 4 digit year.

If you are working far into the past or future you can acquire a 5 or more digit result for the year, but you can't use more than a 4 digit year for input. Nor can you acquire a result or use an input less than 1/1/0001

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Yesterday date

Post by Identis » Mon Mar 20, 2023 11:50 am

JRL wrote:
Fri Mar 17, 2023 1:54 pm
This should work in version 4 onward.

Code: Select all

//Pure Macro Scheduler
Month>mm
Day>dd
Year>yyyy

Let>today=%mm%/%dd%/%yyyy%
Sub>today,1
//Variable today is now yesterday's date.
MDL>today

//Or VBScript
VBStart
VBEnd

VBEval>now-1,yesterday
MDL>yesterday
//The result is date and time
//To have only the date
Separate>yesterday,space,vNow

MDL>vNow_1

Thank you!!!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1378
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Yesterday date

Post by Dorian (MJT support) » Fri Apr 14, 2023 4:36 pm

JRL wrote:
Fri Mar 17, 2023 6:05 pm
I don't want to change my regional date setting to test but as I recall GetDate> presents in the format specified in regional settings. For Add> and Sub> to work with a date the date has to be in month/day/year format. No other format will work.
I just had reason to try this and can confirm that the Sub method still works even if the local date format is DD/MM/YYYY. I also tested Add, and that worked too.

Code: Select all

//My local (UK) format DD/MM/YYYY
//Output : 14/04/2023
GetDate>today

//Output : 13/04/2023
Sub>today,1
Yes, we have a Custom Scripting Service. Message me or go here

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