How to get the integer value of day of week

akshaykumar6 picture akshaykumar6 · Feb 8, 2012 · Viewed 216.4k times · Source

How do I get the day of a week in integer format? I know ToString will return only a string.

DateTime ClockInfoFromSystem = DateTime.Now;
int day1;
string day2;
day1= ClockInfoFromSystem.DayOfWeek.ToString(); /// it is not working
day2= ClockInfoFromSystem.DayOfWeek.ToString(); /// it gives me string

Answer

Joe picture Joe · Feb 8, 2012

Use

day1 = (int)ClockInfoFromSystem.DayOfWeek;