Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i got data from PDF 01-jan-2019 in this format but i want to convert date in  01-01-2019 in asp.net C#


What I have tried:

i thing only way to do that compare the string and set predefined number
Posted
Updated 13-Jan-22 1:01am

1 solution

Take the date as a string in the current text format: "01-jan-2019" and use TryParseExact to convert it to a DateTime value.
You can then use ToString to output it in any format you want: Formatting a DateTime for display - format string description[^]

C#
string input = "01-jan-2019";
DateTime dt;
if (DateTime.TryParseExact(input, "dd-MMM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
    {
    Console.WriteLine(dt.ToString("dd-MM-yyyy"));
    }
 
Share this answer
 

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