Code to run every other day

I need to write some code to switch between two different videos on our website.  My boss would prefer doing a Monday/Wednesday/Friday arrangement one week, and then Tuesday/Thursday the next week.  What is the best way to automate this?
centdevsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge SanchezSoftware EngineerCommented:
Use this code:
int week = DatePart(DateInterval.WeekOfYear, System.DateTime.Today);
    DayOfWeek d = Today.DayOfWeek;
    if (week % 2) {
        if (d == DayOfWeek.Monday | d == DayOfWeek.Wednesday | d == DayOfWeek.Friday) {
        }
        //Do Job
    }
    else {
        if (d == DayOfWeek.Tuesday | d == DayOfWeek.Thursday) {
        }
        //Do Job
    }

Open in new window

0
centdevsAuthor Commented:
This looks pretty close, there's still one other piece that I'm not sure how to handle in here though.  I can set the file name in the if blocks, and this code would work fine then for one week.  The next week though, the schedule reverses, showing the previous T/TH video on MWF, and vice versa.  Any ideas on how to handle that piece?
0
Jorge SanchezSoftware EngineerCommented:
Say you need to switch the 2 videos "myfirstvideo.avi" and "mysecondvideo.avi".
You should use something like this:
    string video1 = "";
    string video2 = "";
    int week = DatePart(DateInterval.WeekOfYear, System.DateTime.Today);
    DayOfWeek d = Today.DayOfWeek;
    if (week % 2) {
        if (d == DayOfWeek.Monday | d == DayOfWeek.Wednesday | d == DayOfWeek.Friday) {
            video1 = "myfirstvideo.avi";
            video2 = "mysecondvideo.avi";
        }
        else {
            video2 = "myfirstvideo.avi";
            video1 = "mysecondvideo.avi";
        }
    }
    else {
        if (d == DayOfWeek.Tuesday | d == DayOfWeek.Thursday) {
            video1 = "myfirstvideo.avi";
            video2 = "mysecondvideo.avi";
        }
        else {
            video2 = "myfirstvideo.avi";
            video1 = "mysecondvideo.avi";
        }
    }

Open in new window

0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

centdevsAuthor Commented:
Is DatePart VB only?  I'm getting a build error on DatePart.
0
Jorge SanchezSoftware EngineerCommented:
Yes, in c# you can use a function like this to get the week of the year:
public int GetYearWeek(DateTime time, string cultureInfo)
{
CultureInfo cul = new CultureInfo(cultureInfo);
return time.Year * 100 + cul.Calendar.GetWeekOfYear(time, cul.DateTimeFormat.CalendarWeekRule, cul.DateTimeFormat.FirstDayOfWeek);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
centdevsAuthor Commented:
Wonderful, thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.