Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int => Weekdayname

Tags:

c#

Is there some inbuilt function to return weekdayname based on value 1-7?

/M

like image 449
Lasse Edsvik Avatar asked Nov 30 '22 11:11

Lasse Edsvik


2 Answers

System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames

more info

like image 65
RvdK Avatar answered Dec 03 '22 00:12

RvdK


for integers from 1 to 7, you'll need to subtract 1 as the array is zero-indexed.

for(int i = 1; i < 8; i++)
{
    Console.WriteLine(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames[i-1]);
}

This will give localised weekday names based on the current culture.

like image 21
ZombieSheep Avatar answered Dec 03 '22 01:12

ZombieSheep