views:

51

answers:

4

Hello,

is there any ready to go solution within the microsoft framework, regarding conversion of date to day?

For example, i would like to convert this string 21/03/2010 (dd/mm/yyyy) to Sunday

+1  A: 

This code will print Sunday on the console window

    Dim dateToShow as DateTime =  new DateTime(2010, 03,21)

    Console.WriteLine(dateToShow.DayOfWeek.ToString)
simon_bellis
I recommend you include a DateTime.Parse() statement in your code sample to explain how to parse his original input of "21/03/2010" rather than just hard-coding it.
Maxim Zaslavsky
+2  A: 
Dim d = DateTime.Parse("21/03/2010").DayOfWeek()
JTA
A: 

I would use DateTime.TryParse() just to validate the user input.

Dim input As String = "2010/12/23"
Dim dateTime As DateTime
If DateTime.TryParse(input, dateTime) Then
    Console.WriteLine(dateTime.DayOfWeek)
Else
    Console.WriteLine("Invalid")
End If
ydobonmai
+1  A: 

This should print "Sunday".

   string myDateTimeString = "21/03/2010";

   DateTime dt = DateTime.ParseExact(
        myDateTimeString, "dd/MM/yyyy", 
        new CultureInfo("en-Us", true)
        , DateTimeStyles.NoCurrentDateDefault);

   Console.WriteLine(dt.DayOfWeek);
TheMachineCharmer