Question

I am trying to learn or generate any codes to learn string day("26.02.2009") ---> give me "wednesday"

I need a static datefunction in C#.

For example:

datetime Str_day= Returnstringdate("09.02.2009");  ---->Str_day="Monday";

Returnstringdate("09.02.2009")

{
     it must return Monday!!!
}

OR

Returnstringdate("09.02.2009 12:30:32")

{
     it must return Monday!!!
}

No correct solution

OTHER TIPS

DateTime.ParseExact allows you to specify the exact format of the date you are parsing. You can then use ToString("dddd") to return the day of the week as a string.

DateTime date = DateTime.ParseExact("09.02.2009", "dd.MM.yyyy", 
    CultureInfo.InvariantCulture);

string dayOfWeek = date.ToString("dddd");

Alternatively you can use the DayOfWeek property, which returns a System.DayOfWeek enumeration value.

DateTime date = DateTime.ParseExact("09.02.2009", "dd.MM.yyyy", 
    CultureInfo.InvariantCulture);

DayOfWeek day = date.DayOfWeek;
string dayString = day.ToString("G");

Though this second option will yield the day of the week as an unlocalized (English) string.

    DayOfWeek day = DateTime.ParseExact(
        "26.02.2009", "dd.MM.yyyy", CultureInfo.InvariantCulture).DayOfWeek;
    string dayString = day.ToString();

Use the DateTime.DayOfWeek Property on your DateTime object.

Also see this thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top