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?
Use DateTime. DayOfWeek property to display the current day of week. DayOfWeek wk = DateTime.
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.
You want to look at the format strings for the ToString method. MyDate. ToString("dddd") will get you what you want.
DateTime. Now. ToString("dddd");
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
Try
CultureInfo.CurrentCulture.DateTimeFormat.DayNames[day No]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With