Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have string date (25.05.2016) ,i want to convert it into (mm/dd/yyyy) format in VB.net.
Please suggest solution.

What I have tried:

I have string date (25.05.2016) ,i want to convert it into (mm/dd/yyyy) format in VB.net.
Please suggest solution.
Posted
Updated 9-May-16 0:12am

It's c# and not vb.net but it should be straight-forward to read and convert.

C#
string ds = "25.05.2016";
DateTime dt;
            
if (DateTime.TryParseExact(ds, "dd.MM.yyyy", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt))
{
    ds = dt.ToString("MM/dd/yyyy");
}


Note, however, that dates don't have a format so there is no such thing as a DateTime class with a certain format, dates only have a format when you convert them to a string.
 
Share this answer
 
Here you find some examples what you can do with the DateTime, DateTime Examples[^].

I guess the way you need to go is first using DateTime.Parse to get a proper Datetime Object and the format it into your desired result.
 
Share this answer
 
Comments
CPallini 9-May-16 6:24am    
5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900