1

Is there any way to set a reminder by Day of the week? For example if I want a reminder every Friday at 10am.

What is the best way to accomplish this task?

I think I've been over thinking some sort of hours calculation. I'm hoping there is a more simplistic way of doing what I'm looking to do.

Update:

My question is more about how to figure out how to set the reminder for a specific day even if it isn't today. So lets say today is Wednesday and I want to set a reminder for every Friday (or ANY day of the week)... How would I accomplish that?

webdad3
  • 8,893
  • 30
  • 121
  • 223

1 Answers1

3

Since the reminder needs a DateTime its pretty easy. Each application has a max of 50 reminders:

DateTime dateTime = DateTime.Now; //First Friday at 10am
for (int i = 0; i < 50; i++)
{
    Reminder reminder = new Reminder("MyReminder")
    reminder.Content = "Reminder";
    reminder.BeginTime = dateTime.AddDays(i * 7);

    ScheduledActionService.Add(reminder);
}

-or this may work-

Reminder reminder = new Reminder("MyReminder")
reminder.Content = "Reminder";
reminder.BeginTime = DateTime.Now; //First Friday at 10am
reminder.Content = "Reminder";
reminder.ExpirationTime = DateTime.Now.AddDays(52 * 7);
reminder.RecurrenceType = RecurrenceInterval.Weekly; 

ScheduledActionService.Add(reminder);

EDIT

This is how you get the next day of week

private DateTime GetNextDay(string dayOfWeek)
{
    for (int i = 0; i < 7; i++)
    {
        DateTime currentDateTime = DateTime.Now.AddDays(i);
        if (dayOfWeek.Equals(currentDateTime.ToString("dddd")))
            return currentDateTime;
    }

    return DateTime.Now;
}
MyKuLLSKI
  • 5,285
  • 3
  • 20
  • 39
  • what is today isn't Friday? My question is more about how to figure out how to set the reminder for a specific day even if it isn't today. So lets say today is Wednesday and I want to set a reminder for every Monday... How would I accomplish that? – webdad3 Feb 16 '12 at 06:10
  • ugh your question should be revised. This is a more general c# question – MyKuLLSKI Feb 16 '12 at 06:23
  • Then just change the Time portion of the return to x o'clock – MyKuLLSKI Feb 16 '12 at 07:00
  • That worked like a champ! Thank you. I will now use the GetNextDay with the Reminder code to do what I wanted. – webdad3 Feb 16 '12 at 13:06