A script to derive the day of the year (001-365) ?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Jerry Gilels
Newbie
Posts: 6
Joined: Tue Sep 16, 2003 2:22 pm
Contact:

A script to derive the day of the year (001-365) ?

Post by Jerry Gilels » Tue Sep 16, 2003 2:56 pm

Marcus once sent me a script to derive the day of the year in MacroScheduler. I had a, let's say, C-R-A-S-H a short time ago and lost many things. Once of them, this MacroScheduler scp. I do not have VB, so does anyone have a script that does this in a nice, understandable way?

Jerry.

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Tue Sep 16, 2003 4:05 pm

Try this. :)VBSTART
Function DayOfYear
DayOfYear = Abs(DateDiff("d","01/01/" & Year(Now),Now))
End Function
VBEND

VBEval>DayOfYear,DayCount
MessageModal>Days so far this year : %DayCount%

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Tue Sep 16, 2003 4:11 pm

And then after I hit submit, I see "do not have VB". (Consider upgrading ;) )

There have been a few threads about such a "Date Count" script. Here is one shows how to count without VB: http://www.mjtnet.com/usergroup/viewtopic.php?t=210

Here's an example for your use:Let>DateStart=1/1/2003
Let>DayCount=0
GetDate>Today

Label>CheckIfToday
If>Today=DateStart,TodayFound
Sub>Today,1
Add>DayCount,1
Goto>CheckIfToday

Label>TodayFound
MessageModal>Non-VB day count = %DayCount%

The VBScript version runs almost instantly, but the Non-VB version can take a few seconds.

Jerry Gilels
Newbie
Posts: 6
Joined: Tue Sep 16, 2003 2:22 pm
Contact:

Post by Jerry Gilels » Tue Sep 16, 2003 4:22 pm

I don't have VB....

[quote="Captive"]Try this. :)VBSTART
Function DayOfYear
DayOfYear = Abs(DateDiff("d","01/01/" & Year(Now),Now))
End Function
VBEND

VBEval>DayOfYear,DayCount
MessageModal>Days so far this year : %DayCount%[/quote]

Jerry Gilels
Newbie
Posts: 6
Joined: Tue Sep 16, 2003 2:22 pm
Contact:

This one works like a charm...

Post by Jerry Gilels » Tue Sep 16, 2003 5:07 pm

Thanks. It works like a charm...

Two things:

1. The date is dependent on your Windows regional settings.
2. The DayCount loop has to start with a value of 1.

Finally, I almost used a flat file read approach, which also would have worked. But, your solution is simpler and more elegant. Does the read approach run faster? Hmmm.... maybe I should try it just for the heck of it.

Anyway, thanks again for your help.

Jerry.



[quote="Captive"]And then after I hit submit, I see "do not have VB". (Consider upgrading ;) )

There have been a few threads about such a "Date Count" script. Here is one shows how to count without VB: [url]http://www.mjtnet.com/forum/viewtopic.php?t=210[/url]

Here's an example for your use:Let>DateStart=1/1/2003
Let>DayCount=0
GetDate>Today

Label>CheckIfToday
If>Today=DateStart,TodayFound
Sub>Today,1
Add>DayCount,1
Goto>CheckIfToday

Label>TodayFound
MessageModal>Non-VB day count = %DayCount%

The VBScript version runs almost instantly, but the Non-VB version can take a few seconds.[/quote]

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Re: This one works like a charm...

Post by Captive » Tue Sep 16, 2003 5:28 pm

Jerry Gilels wrote:1. The date is dependent on your Windows regional settings.
Which makes the VBScript even better. If it is a problem, you can probably get around it by reading a registry string somewhere, or figuring out by analying the results of GetDate (and then just getting the date of tomorrow/yesterday, to see which entry changed and thus is the date field.)
Jerry Gilels wrote:2. The DayCount loop has to start with a value of 1.
Ahh right. I was basing it off the number of days *since* 01/01.

A request if I may - please don't quote all of the previous message whenever you make a post. Both times my message was right there, above your post.

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