Problem with date format

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
cioberto

Problem with date format

Post by cioberto » Wed Aug 04, 2004 7:29 am

Hello.
I´m having problems with the dates and I´m going crazy.
I want to calculate the last day of the previous month in which I´m executing the macro. So I use this code:

Day>myday
Month>mymonth
Year>myyear
Let>thedate=%myday%/%mymonth%/%myyear%
Let>theend=0
Repeat>theend
Sub>thedate,1
MidStr>thedate,4,2,AuxMonth
If>AuxMonth=mymonth,Finded
Let>theend=1
Label>Finded
Until>theend,1

But, usually all my dates are dd/mm/yyyy (that is what i have in the regional settings). When i schedulle the macro, the sub function use thedate as mm/dd/yyyy but only sometimes. I close the macro scheduler i open it again, and the macro run as dd/mm/yyyy. I scheduled the task again and again i loose that settings.

Do you know any solution? Is this a bug?
Thanks to all of you in advance.

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 » Wed Aug 04, 2004 3:39 pm

The date format is going to use same format as Regional settings.

When you are building %thedate% you are forcing 2 digit days and months with leading zeroes, the values are treated as strings.
When you are subtracting date by one day the result is coming back in Regional Settings format. The values are now treated as numbers since you did a math function.
Example:
your value for thedate = 08/04/2004
subtracting 1 results = 8/3/2004

Now when you do MidStr you are getting "/2" vs. the "03" that you want.

Turn on the WatchList and single step through your script.
If you put in "GetDate>the date" at the top, you will see the system format that is being used. The Day>, Month> functions are using 2 digit formats with leading zeroes even if the GetDate> format is not.
=========================

But even if this is a bug, there are 2 possible workarounds until this is changed:
1. You may want to modify the script to check for leading zeroes and insert them if needed, or use a different MidStr routine (Need multiple versions based on 1/2 digits in month and/or day positions).
OR
2. You may want to modify your Regional Settings, but remember that any change there will affect all of your other programs.
======================

You can eliminate the leading 0 from the month and day by subtracting 0 which will make them numbers, like this:
Day>myday
Month>mymonth
Year>myyear
Sub>myday,0
Sub>mymonth,0
Let>thedate=%myday%/%mymonth%/%myyear%

You could also do that with AuxMonth:
MidStr>thedate,4,2,AuxMonth
Sub>AuxMonth,0
If>AuxMonth=mymonth,Finded

But you will still have the problem of MidStr not know where to start. So you will still need to look for leading zeroes in %thedate%
====================

Is this a bug? Could be. I think that some change should be made to make it consistent. I think having the Day>, Month> commands be same format as GetDate> and Regional settings would be best.

(Have not checked, but wonder if GetTime> may have same issue with Hour>, Min>, Sec> ?)
====================
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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