Click here to Skip to main content
15,848,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to read a string like ("05.10/2012 5:30:29 PM") and use it in a DateTime value ?


Try this:
DateTime myDateTime = DateTime.Parse("05.10/2012 5:30:29 PM");

DateTime myDateTime;
DateTime.TryParse("05.10/2012 5:30:29 PM", out myDateTime)

More information:[^]
Share this answer
mrmarzban 24-Jun-12 5:57am    
I'm looking for a way to calculate how many seconds or minutes is between two dates ?
Shahin Khorshidnia 24-Jun-12 6:14am    
Is it a new question?
Assuming each date is on a separate line, you can read them all with
string[] lines = File.ReadAllLines(path);

You can then convert each one to a DateTime using Datetime.ParseExact, or DateTime.TryParseExact:
foreach (string line in lines)
   DateTime dt = DateTime.ParseExact(line, "dd.MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);

There is a list of DateTime format codes here: Formatting a DateTime for display - format string description[^]
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