DayOfWeek -1 returning odd date

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

DayOfWeek -1 returning odd date

Post by Tourless » Thu Jun 07, 2018 6:50 pm

Hi Folks,
I have the following code returning 06/03/2002 & 06/03/0201, respectively. If I run it again I get a completely different set of dates.

DayOfWeek>dow
GetDate>the_date
Sub>the_date,{%dow%-1}
SetFocus>Report Options
Send> %the_date%
Press Tab
Send> %the_date%

What am I doing wrong?

Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Re: DayOfWeek -1 returning odd date

Post by Tourless » Thu Jun 07, 2018 8:36 pm

I'm getting closer but can't figure out why the following produces a date formatted as mm/d/yyyy. When I run the same code and comment out 'Let>dd=dd-1 the result is proper at mm/dd/yyyy. Why does subtracting 1 from the date remove the leading zero? How and I fix this?
Press Enter
Month>mm
Day>dd
Year>yyyy
Let>dd=dd-1
MessageModal>%mm%/%dd%/%yyyy%

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: DayOfWeek -1 returning odd date

Post by Grovkillen » Thu Jun 07, 2018 8:51 pm

Code: Select all

Month>mm
Day>dd
Year>yyyy
Let>dd=dd-1
If>dd<10
 Let>dd=0%dd%
Endif>
MessageModal>%mm%/%dd%/%yyyy%
Let>ME=%Script%

Running: 15.0.24
version history

Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Re: DayOfWeek -1 returning odd date

Post by Tourless » Thu Jun 07, 2018 9:00 pm

brilliant, thank you so much!

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: DayOfWeek -1 returning odd date

Post by Grovkillen » Fri Jun 08, 2018 4:15 am

Great, but a reflection: what do you do if the current day is the first day of the month? The code above would then compute a date with invalid number, i.e 06/00/2018
Let>ME=%Script%

Running: 15.0.24
version history

Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Re: DayOfWeek -1 returning odd date

Post by Tourless » Fri Jun 08, 2018 2:56 pm

that's a good question... so can I simply say today-1?
edit:
yes, yes I can...
GetDate>today
DateAdd>today,dd,-1,strDate
MessageModal>%strDate%

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