Newbie Date Parsing question

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

Newbie Date Parsing question

Post by adunaway » Tue Sep 05, 2006 9:00 pm

I need to enter today's date in a field.

The format is mm/dd/yy, but since the field on the application is set for mm/dd/yy format, I will only need to enter the actual numbers. For instance, if todays date was 12/24/2005, I would only need to send 122405 to the screen.

The GetDate function returns dates in the mm/dd/yyyy format.

How can I use variables to parse the 12/24/2005 (which is returned from getdate) to get 122405.

Thanks in advance!

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

Post by JRL » Tue Sep 05, 2006 9:09 pm

You can easily parse the results of Getdate using Midstr>

Getdate>today
Midstr>today,1,2,mm
Midstr>today,4,2,dd
Midstr>today,9,2,yy

Or:
Instead of GetDate> try the separate functions day>, month> and year>.

Day>dd
Month>mm
Year>yy

//Since Year will no doubt show up as a four digit number we will need to trim it with midstr>.

Midstr>yy,3,2,yy


Hope this helps,
Dick

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

Post by Me_again » Tue Sep 05, 2006 9:15 pm

...and just to show there's always another way to do anything, the one line conversion using Separate :wink:

GetDate>mydate
Separate>mydate,/,part
MessageModal>%mydate% %part_1% %part_2% %part_3%


Actually that MidStr parse isn't very portable, it wouldn't work on the PC I'm using because GetDate returns 9/5/2006.

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

Post by Marcus Tettmar » Tue Sep 05, 2006 9:24 pm

Always better to use Day, Month and Year because they are unambiguous whereas GetDate is dependent on regional settings.
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
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Sep 05, 2006 9:37 pm

That's important information. I would have assumed that day>, month> and Year> were also tied to regional settings. Since all computers within my sphere of influence were set up by me, they all have the same (USA central time windows default) regional setting. Since Getdate> magically provides the same format as month/day/year it never occured to me to check out the differences.

Too bad, I liked the Separate> solution.

Later,
Dick

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

Post by Marcus Tettmar » Tue Sep 05, 2006 9:45 pm

GetDate returns the date in the format of the short date as set up in regional settings. The help file says "The format of the date depends on the regional settings of the system."

In contrast:

Day - returns the day as a number with a leading zero (01-31).
Month - returns the month as a number with a leading zero (01-12).
Year - returns the year as a four-digit number (0000-9999).

Therefore they are independent of any regional settings.

So I would ALWAYS use Day, Month and Year when formatting dates where you want control of the format.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Thanks everyone

Post by adunaway » Wed Sep 06, 2006 3:29 pm

it worked perfect

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