How to know which day of the week from the calendar

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

How to know which day of the week from the calendar

Post by timle » Tue Nov 13, 2007 10:37 pm

if I have a file 11-11xxxx
how do the script know 11of nov is sunday to change it to
sunxxxx

thanks

Rory
Pro Scripter
Posts: 50
Joined: Thu Mar 23, 2006 2:50 pm
Location: Wisconsin

Post by Rory » Wed Nov 14, 2007 3:30 am

If you want to out put the day of the week as text, the following will do that for you. This is taken from Macro Scheduler Help with a little added in to format the date as requested.

Rory


Month>month_result
Year>year_result
Day>day_result
DayOfWeek>result
Goto>Day%result%

Label>Day1
Let>DayString=Sunday
Goto>Continue

Label>Day2
Let>DayString=Monday
Goto>Continue

Label>Day3
Let>DayString=Tuesday
Goto>Continue

Label>Day4
Let>DayString=Wednesday
Goto>Continue

Label>Day5
Let>DayString=Thursday
Goto>Continue

Label>Day6
Let>DayString=Friday
Goto>Continue

Label>Day7
Let>DayString=Saturday
Goto>Continue

Label>Continue

If>month_result=1
Let>Month=January
ENDIF
If>month_result=2
Let>Month=February
ENDIF
If>month_result=3
Let>Month=March
ENDIF
If>month_result=4
Let>Month=April
ENDIF
If>month_result=5
Let>Month=May
ENDIF
If>month_result=6
Let>Month=June
ENDIF
If>month_result=7
Let>Month=July
ENDIF
If>month_result=8
Let>Month=August
ENDIF
If>month_result=9
Let>Month=September
ENDIF
If>month_result=10
Let>Month=October
ENDIF
If>month_result=11
Let>Month=November
ENDIF
If>month_result=12
Let>Month=December
ENDIF

MessageModal>%DayString%, %Month% %day_result%, %year_result%

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

It does not work all the time

Post by timle » Wed Nov 14, 2007 5:12 am

The script can out put the date as text, but it wouldnot work all the time let say I have a file name:
11-11xxxx. for november, the 11th is Sunday, so =Nov-11Sundayxx
if I have a file 12-11xxxx, the 11th is now Tuesday not Sunday.

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

Post by Marcus Tettmar » Wed Nov 14, 2007 9:49 am

Here's how I would do it. I'm assuming the year is 2007. You don't specify the year anywhere, and that would of course have a bearing on the day of the week:

Code: Select all

VBSTART
  Dim DayArray
  DayArray = array("sun","mon","tue","wed","thu","fri","sat")
VBEND

Let>FileName=12-11xxxx.txt

Let>Month={Copy(%FileName%,1,2)}
Let>Day={Copy(%FileName%,4,2)}

VBEval>WeekDay(DateSerial(2007,%Month%,%Day%)),d
VBEVal>DayArray(%d%),DayName

Let>rest={Copy(%FileName%,6,Length(%FileName%))}

Let>NewFile=%DayName%%rest%
MessageModal>NewFile
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Thankyou

Post by timle » Wed Nov 14, 2007 4:11 pm

so if the year is different, I just change the year in the script right?

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

Post by Marcus Tettmar » Wed Nov 14, 2007 4:14 pm

Yes. If the year is always to be the current year then you could just change the code to:

Code: Select all

VBSTART
  Dim DayArray
  DayArray = array("sun","mon","tue","wed","thu","fri","sat")
VBEND

Let>FileName=12-11xxxx.txt

Let>Month={Copy(%FileName%,1,2)}
Let>Day={Copy(%FileName%,4,2)}

VBEval>WeekDay(DateSerial(Year(Now),%Month%,%Day%)),d
VBEVal>DayArray(%d%),DayName

Let>rest={Copy(%FileName%,6,Length(%FileName%))}

Let>NewFile=%DayName%%rest%
MessageModal>NewFile
Note 2007 has been replaced with Year(now)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

dayname is one day ahead

Post by timle » Wed Nov 14, 2007 9:58 pm

when I change FileName=11-11xxxx.txt

the NewFile= monday the correct date should be Sunday


if I change the date to11-10xxx.txt, I have vbscript error
thanks
Last edited by timle on Wed Nov 14, 2007 10:16 pm, edited 1 time in total.

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

Post by Marcus Tettmar » Wed Nov 14, 2007 10:07 pm

Oops. I forgot the array indexing starts with 0. So you need to subtract one from the day number. The correct code is:

Code: Select all

VBSTART
  Dim DayArray
  DayArray = array("sun","mon","tue","wed","thu","fri","sat")
VBEND

Let>FileName=11-11xxxx.txt

Let>Month={Copy(%FileName%,1,2)}
Let>Day={Copy(%FileName%,4,2)}

VBEval>WeekDay(DateSerial(Year(Now),%Month%,%Day%)),d
VBEVal>DayArray(%d%-1),DayName

Let>rest={Copy(%FileName%,6,Length(%FileName%))}

Let>NewFile=%DayName%%rest%
MessageModal>NewFile
I think that should fix it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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