Get day from DateTime using C#

user9969 picture user9969 · Jun 7, 2010 · Viewed 77.5k times · Source

Silly question. Given a date in a datetime and I know it's tuesday for instance how do i know its tue=2 and mon=1 etc...

Thanks

Answer

Paolo Tedesco picture Paolo Tedesco · Jun 7, 2010

You are looking for the DayOfWeek property.
Then, as Dan suggests in the comment below, just look at the integer value of the enum to get the day as integer:

int d = (int)System.DateTime.Now.DayOfWeek