Click here to Skip to main content
15,921,212 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the date from given string in C#

here is my code

string dateString = "20091229T213000";

string may enter by users. how to extract the date from the plain string in below mentioned format.

output required is in dd-MMM-yyyy

Thanks in Advance
Posted

Use DateTime.ParseExact[^] for that...
C#
DateTime.ParseExact("20091229T213000", "yyyyMMddTHHmmss", CultureInfo.InvariantCulture);
 
Share this answer
 
v2
Please try the below code
C#
string dateString = "20091229T213000";
dateString = DateTime.ParseExact(dateString, "yyyyMMddTHHmmss", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-yyyy");
 
Share this answer
 
Use
DateTime.TryParse
 
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