Yet another newbie date 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

Yet another newbie date question

Post by adunaway » Wed Oct 11, 2006 1:42 pm

My needs:
Get today's Date
Subtract 10 days from current date
Parse out 2 digit day, 2 digit month, and 2 digit year

I can use GetDate and Sub to get the date 10 days ago. This causes problem w/ MidStr when I am trying to parse out the pieces since MidStr requires a positional starting point. The starting point will be different on every GetDate call since it will return a 1 digit month sometimes and a 2 digit month sometimes. The same goes for the day.

I can use the Month Day and Year functions to parse out the pieces I need, but then I cannot subtract 10 days from the date because the Date function has no month as a reference.

Is there an easy method of accomplishing what I need without creating horrendous IF statements?

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

Post by JRL » Wed Oct 11, 2006 2:08 pm

This works for me.

Code: Select all

Month>mm
Day>dd
Year>yyyy
Concat>mm,/%dd%/%yyyy%
sub>mm,10
Midstr>mm,1,2,mon
Midstr>mm,4,2,dy
Midstr>mm,9,2,yr
Hope it works for you,
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 » Wed Oct 11, 2006 2:37 pm

Or:

Code: Select all

VBSTART
VBEND

VBEval>Year(Date()-10),yy
VBEval>Month(Date()-10),mm
VBEval>Day(Date()-10),dd
Also look at VBScript's FormatDateTime function:
http://msdn.microsoft.com/library/en-us ... frame=true
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

JRL - problem

Post by adunaway » Wed Oct 11, 2006 2:39 pm

I tried something like this originally but it still has a problem.

Lets take today for instance...

your script will make mm = 10/1/2006
when you say MidStr>mm,4,2,dy it = 1/ instead of 01

I guess I will do this but create an IF that says to concatenate a 0 in front of DD if it's less than 10.

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

Post by JRL » Wed Oct 11, 2006 2:44 pm

Maybe it has to do with Regional Settings in Windows? On my computer I get a 2 digit day, a 2 digit month and a 4 digit year.

This is my 500th post! Hope its the correct answer for you.

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

Post by Marcus Tettmar » Wed Oct 11, 2006 2:47 pm

As stated previously, GetDate returns a date in ShortDate format in accordance with your regional settings. Avoid using it if you want a portable 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?

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

Post by JRL » Wed Oct 11, 2006 2:49 pm

Marcus,

I think the problem occurs possibly with his regional settings when he performs the sub>

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

regional settings

Post by adunaway » Wed Oct 11, 2006 4:58 pm

Hey guys,

I just changed the regional settings and used midstr to get what I needed. That seemed to make everything very simple.

Thanks for your help!

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