troubleshooting Question

Convert Date From dd/MM/yyyy Format To MM/dd/yyyy Format in VB.NET

Avatar of Nolanc
Nolanc asked on
Visual Basic.NET
4 Comments1 Solution782 ViewsLast Modified:

I have the following Function in my application:

Public Function ToSqlDate(ByVal PassDate As Date) As Date
       Return Date.Parse(PassDate.Month.ToString & "/" & PassDate.Day.ToString & "/" & PassDate.Year.ToString)
End Function

I call the function as follows:

SqlStart = ToSqlDate(StartDate) Where SqlStart has DataType "Date" and StartDate is a date value in a DateTimePicker Control.

When I run the application it abends with a message "String Was Not Recognised As Valid DateTime).

At this point in time when I hover the mouse over PassDate it displays a value of #9/30/2010# whereas I passed a value of 30/09/2010.

My Regional Setting for date is dd/MM/yyyyy.

The reason I must convert the Date to MM/dd/yyyy is that SQL requires it in this format in order to make comparisons with dates.

Any ideas or recommendations how I can get around this problem.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros