Convert date format

How can I convert a string (date) to this format ("MM/dd/yyyy")?
3/1/2015 or 3/12/2015
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

myDate = today.tostring("MM/dd/yyyy")
VBdotnet2005Author Commented:
Is your sample just convert today to a string format?
I'm not sure what kind of conversion you want to do. Is the input string in a different form, like "March 1, 2015"? Should the output be a string or a date type? Do you need to worry about alternate date formats (European dd/mm/yyyy, etc.)?

You may want to look at the Date.Parse method, depending on exactly what you want to do.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Lokesh B RDeveloperCommented:
string date = DateTime.Now.ToString("MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kaushal AroraTechnical AnalystCommented:
Dear VBdotnet2005,

Kindly go through these links:

Hope these help you in solving your problem.

Kaushal Arora
Gustav BrockCIOCommented:
If your "date" is a string, you need to parse it first:
Dim TxtDate As String
Dim DatDate As Date
Dim MyDate As String

TxtDate = "3/12/2015"

DatDate = DateTime.Parse(TxtDate, System.Globalization.CultureInfo.InvariantCulture)

MyDate = DatDate.ToString("MM'/'dd'/'yyyy")

' Or in one line, should you prefer:
MyDate = DateTime.Parse(TxtDate, System.Globalization.CultureInfo.InvariantCulture).ToString("MM'/'dd'/'yyyy")

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.