views:

146

answers:

6

Hi.

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

+1  A: 
DateTime.DayOfWeek
Rik
A: 

Yes DateTime has DayOfWeek() method.

Arseny
+4  A: 

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
Paolo Tedesco
Sorry i posted the wrong question.Apologies.Given that I know it's thursday how do I map to a number EG monday=1tue=2 etc..so given the date I need to know that is monday and =1 how do i do that?
How do you know Monday == 1? By looking at the enum!
Dan Puzey
@devnet maybe you should follow the link and read. The clear example shows the usage and output. ("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek) gives The day of the week for 5/1/2003 is Thursday.
PoweRoy
@devnet247: Are you also looking for this: `System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek`
Bobby
+1  A: 

Hi if you want to find out the name of the day, you can do this as follows:

DateTime.Now.DayOfWeek

Response.Write(DateTime.Now.DayOfWeek);
Vijjendra
DateTime.Now.DayOfWeek.ToString() will give name of day
AsifQadri
+1  A: 

DayOfWeek is an Enum. To get the integer instead of the string representation you can cast it

int i = (int)d.DayOfWeek
Morten Anderson