tags:

views:

48

answers:

3

Using VB.Net 2005

I want to get a day for the date.

My Datepicker format is Custom Format (dd/MM/yyyy)

Code.

Dim dt As New DateTime()
dt = Format(textdate.Text, "dd/MM/yyyy")
textday.Text = dt.DayOfWeek.ToString

When i try to run the above code, it was taking only this format(MM/dd/yyyy)

Suppose

Date - 02/05/2010

It should display as "Tuesday of Feburary" but it is displaying as "Sunday of May"

Need VB.Net code Help

A: 

date format always depend on the regional setting of the current computer, in your example the instance where this code run expect mm/dd/yyyy

to fix this, you need to change the regional setting of the application

Fredou
+3  A: 

You should have a look at

DateTime.TryParseExact Method (String, array [] () [], IFormatProvider, DateTimeStyles, DateTime)

It should be something similar to

Dim dt As New DateTime()
DateTime.TryParseExact("02/05/2010", "MM/dd/yyyy", Nothing, Globalization.DateTimeStyles.None, dt)
astander
+1  A: 

If you're using a DateTimePicker, you shouldn't need to do any formatting in the first place. Just use DateTimePicker.Value to get the value as a DateTime.

I don't know what Format does used like that - I'd have expected a call to DateTime.Parse/ParseExact/TryParse/TryParseExact, as per astander's answer - but it would still be better if you didn't do any parsing at all, and just asked the control for the value.

Jon Skeet