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?
 
jorgesv13Connect With a Mentor Commented:
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
 
jorgesv13Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
jorgesv13Commented:
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
 
centdevsAuthor Commented:
Is DatePart VB only?  I'm getting a build error on DatePart.
0
 
centdevsAuthor Commented:
Wonderful, thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.