Click here to Skip to main content
15,887,988 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 ?
Posted

Hello

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

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


More information: http://msdn.microsoft.com/en-us/library/1k1skd40.aspx[^]
 
Share this answer
 
v2
Comments
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
C#
string[] lines = File.ReadAllLines(path);

You can then convert each one to a DateTime using Datetime.ParseExact, or DateTime.TryParseExact:
C#
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