---
title: "how to parse out date time from a string and match with a given format"  
description: "how to parse out date time from a string and match with a given format"  
author: "Anonymous User"  
published: 2013-12-12  
updated: 2013-12-12  
canonical: https://www.mindstick.com/forum/1765/how-to-parse-out-date-time-from-a-string-and-match-with-a-given-format  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# how to parse out date time from a string and match with a given format

My [datetime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) value is [stored](https://www.mindstick.com/forum/157561/what-is-the-stored-procedure-create-a-procedure-to-find-the-record-by-stu_id-from-the-student-table) in the [column as](https://www.mindstick.com/forum/159334/how-to-set-column-as-auto_increment-in-mysql) 12/03/2013 12:00 am, I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to parse out the date from a different column which is a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) so i check to see if the datetime is a valid date. I can not [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) out the [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format), yyyy-mm-dd hh:mm tt doesnt seem to make the [condition](https://www.mindstick.com/forum/12711/select-query-with-and-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;

}

## Replies

### Reply by Pravesh Singh

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;}
```


---

Original Source: https://www.mindstick.com/forum/1765/how-to-parse-out-date-time-from-a-string-and-match-with-a-given-format

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
