Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

Convert date format

How can I convert a string (date) to this format ("MM/dd/yyyy")?
3/1/2015 or 3/12/2015
Avatar of sirbounty
sirbounty
Flag of United States of America image

myDate = today.tostring("MM/dd/yyyy")
Avatar of VBdotnet2005

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Lokesh B R
Lokesh B R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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")
Console.Writeline(MyDate)

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

Open in new window

/gustav