Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi

I have an issue to convert the date into the format(dd-MM-yyyy) and (yyyyMMdd)

I have used the txtsodate.text.ToString("yyyyMMdd") but failed.

How can set the date format in the above format. Pls advice me

Maideen
Posted
Updated 10-Oct-18 0:58am
Comments
Sergey Alexandrovich Kryukov 22-Dec-14 23:44pm    
This is not how it works. You should not try to create a format provider from string. (Where did you get this weird idea?) This interface is implemented by, for example, System.Globalization.CultureInfo.
—SA

1 solution

If you have a string with the date you can first convert it to the DateTime[^] type and then back to a string again in the format you prefer.

For example:
C#
string inputData = "12/23/2014";   // American style
DateTime tmpDate = DateTime.ParseExact(inputData, "MM/dd/yyyy", null);
string output1 = tmpDate.ToString("dd-MM-yyyy");
string output2 = tmpDate.ToString("yyyyMMdd");


Here is a good page with different date formats Custom Date and Time Format Strings[^]
 
Share this answer
 
Comments
aarif moh shaikh 22-Dec-14 23:38pm    
good one...

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