Member 14075859 wrote:
i gave up lol
Hey, don't give up!
Please, see this MSDN article:
Performing arithmetic operations with dates and times | Microsoft Docs[
^]
There's the most information you need to handle your problem.
Note: you can write a programme which operates on dates:
CultureInfo ci = new CultureInfo("en-us");
DateTime givenDay = new DateTime(2019,01,01);
DateTime prevDay = givenDay.AddDays(-1);
DateTime nextDay = givenDay.AddDays(1);
Console.WriteLine("given day: {0} ({1})", givenDay.ToString("yyyy-MM-dd"), givenDay.ToString("dddd", ci));
Console.WriteLine("prev day: {0} ({1})", prevDay.ToString("yyyy-MM-dd"), prevDay.ToString("dddd", ci));
Console.WriteLine("next day: {0} ({1})", nextDay.ToString("yyyy-MM-dd"), nextDay.ToString("dddd", ci));
Result:
given day: 2019-01-01 (Tuesday)
prev day: 2018-12-31 (Monday)
next day: 2019-01-02 (Wednesday)
or on enums (
Enumeration types - C# Programming Guide | Microsoft Docs[
^]):
public enum WeekDays { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
int givenDay = (int)WeekDays.Sunday;
int prevDay = givenDay-1;
if(prevDay<0) prevDay = (int)WeekDays.Saturday;
int nextDay = givenDay+1;
if(nextDay>6) nextDay = (int)WeekDays.Sunday;
Console.WriteLine("given day is: {0} (value of: {1})", Enum.GetName(typeof(WeekDays), givenDay), givenDay);
Console.WriteLine("prev day is: {0} (value of: {1})", Enum.GetName(typeof(WeekDays), prevDay), prevDay);
Console.WriteLine("next day is: {0} (value of: {1})", Enum.GetName(typeof(WeekDays), nextDay), nextDay);
Result:
given day is: Sunday (value of: 0)
prev day is: Saturday (value of: 6)
next day is: Monday (value of: 1)
or even on array (as Richard MacCutchan point me out to the original question):
string[] WeekDays = new string[]{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
Console.WriteLine("Days of week:");
for(int i=0; i<WeekDays.Length; i++)
Console.WriteLine("{0} - {1}", i, WeekDays[i]);
Console.WriteLine("Choose the day (corresponding number):");
string choosenDay = Console.ReadLine();
int givenDay = Int32.Parse(choosenDay);
int prevDay = givenDay-1<0 ? 6 : givenDay-1;
int nextDay = givenDay+1>6 ? 0 : givenDay+1;
Console.WriteLine("given day is: {0} (value of: {1})", WeekDays[givenDay], givenDay);
Console.WriteLine("prev day is: {0} (value of: {1})", WeekDays[prevDay], prevDay);
Console.WriteLine("next day is: {0} (value of: {1})", WeekDays[nextDay], nextDay);
Result:
Days of week:
0 - Sunday
1 - Monday
2 - Tuesday
3 - Wednesday
4 - Thursday
5 - Friday
6 - Saturday
Choose the day (corresponding number):
given day is: Tuesday (value of: 2)
prev day is: Monday (value of: 1)
next day is: Wednesday (value of: 3)