Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I want to get day of the week by inserting the date but using format dd/MM/yyyy

Now this is what i did..

<pre lang="c#">Session["StartDate"]=09/10/2011
string ddMMyyyyFormat = Session["StartDate"].ToString();//Date in dd/MM/yyyy
string MMddyyyFormat =Convert.ToDateTime(ddMMyyyyFormat).ToString("MM/dd/yyyy");

DateTime MMddyyyyDate = Convert.ToDateTime(MMddyyyFormat);
string dayOfWeek = MMddyyyyDate.DayOfWeek.ToString();</pre>

Now i get the day of the week as "Saturday" because its not converted to format MM/dd/yyyy
Posted
Updated 14-Oct-11 18:49pm
v2

C#
session["StartDate"] = 09/10/2011;
string abc = Session["StartDate"].ToString();
DateTime xyz = Convert.ToDateTime(abc);
string dayofweek = xyz.DayOfWeek.toString()


this is working on my machine.
 
Share this answer
 
DayOfWeek is a struct! Just use the int value instead and format it as desired. Demonstration:

Console.WriteLine("{0:00}", (int)DateTime.Now.DayOfWeek);
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900