Home > DeveloperSection > Forums > how to parse out date time from a string and match with a given format
Ashish Pandey

Total Post:128

Points:898
Posted on    December-12-2013 1:46 AM

 C# C# 
Ratings:


 1 Reply(s)
 767  View(s)
Rate this:

My datetime value is stored in the column as 12/03/2013 12:00 am, I am trying to parse out the date from a different column which is a string so i check to see if the datetime is a valid date. I can not figure out the format, yyyy-mm-dd hh:mm tt doesnt seem to make the condition true.

string[] format = new string[] { "yyyy-mm-dd hh:mm tt" };

DateTime datetime;

//12/03/2013 12:00 am

if (DateTime.TryParseExact(userFilters.FilterValue, format, CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out datetime))

{

  DateEntered = datetime;

}



Pravesh Singh

Total Post:411

Points:2881
Posted on    December-12-2013 2:21 AM

Hi Ashish,

You can try this :

string[] format = new string[] { "MM/dd/yyyy hh:mm tt" };

DateTime datetime;

//12/03/2013 12:00 am 

if (DateTime.TryPars eExact(userFilters.FilterValue, format, CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out datetime))

{

 DateEntered = datetime;

}


Don't want to miss updates? Please click the below button!

Follow MindStick