Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Day of a week from integer value of the Day

I have converted several days of the week to their respective integer values..

For example: Tuesday, Thursday, Friday As 2,4,5

Now I need to get back to the days from the integers.

Simply the inverse of what i had done.

Inverse of the Question: Get Integer value of day of week

Is there a simple standard way for getting day of week from integer value in C# or else I will have to perform a manual calculation with a Method?

like image 570
parkourkarthik Avatar asked Aug 21 '14 05:08

parkourkarthik


People also ask

How to get day of week in c#?

Use DateTime. DayOfWeek property to display the current day of week. DayOfWeek wk = DateTime.

How to get day of the week in vb net?

Use the DateTime. DayOfWeek or DateTimeOffset. DayOfWeek property to retrieve a DayOfWeek value that indicates the day of the week. If necessary, cast (in C#) or convert (in Visual Basic) the DayOfWeek value to an integer.

How to get only day from Date in vb net?

You want to look at the format strings for the ToString method. MyDate. ToString("dddd") will get you what you want.

How to find day from Date in asp net c#?

DateTime. Now. ToString("dddd");


2 Answers

try below code :-

Response.Write(Enum.GetName(typeof(DayOfWeek),5)); 

Output:

Friday

and If you have to convert integers to days of week, see following sample to convert “2,4,5″ using LINQ.

var t = string.Join(",",                  from g in "2,4,5".Split(new char[] { ',' })                  select Enum.GetName(typeof(DayOfWeek), Convert.ToInt32(g)));         Response.Write(t); 

Output:

Tuesday,Thursday,Friday 

For extra informations :-

http://msdn.microsoft.com/en-us/library/system.enum.getname(v=vs.110).aspx

like image 53
Neel Avatar answered Sep 19 '22 17:09

Neel


Try

CultureInfo.CurrentCulture.DateTimeFormat.DayNames[day No] 
like image 30
Gumzle Avatar answered Sep 19 '22 17:09

Gumzle