---
title: "Convert a string to a date in .net"  
description: "Convert a string to a date in .net"  
author: "Anonymous User"  
published: 2013-11-14  
updated: 2013-11-14  
canonical: https://www.mindstick.com/forum/1735/convert-a-string-to-a-date-in-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Convert a string to a date in .net

I'm [reading](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists) [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) from a flat [file in c#](https://www.mindstick.com/forum/159903/how-to-create-a-log-file-in-c-sharp) and need to [test](https://yourviews.mindstick.com/story/1427/explosive-facts-about-trinity-test-world-s-first-nuclear-bomb) whether certain [values](https://www.mindstick.com/forum/327/sum-textbox-values) are dates. They could be in either YYYYMMDD [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) or MM/DD/YY format. What is the simplest way to do this in .Net?

## Replies

### Reply by Anonymous User

Hi chintoo,

```
string dateTime = "01/08/2008 14:50:50.42";            DateTime dt = Convert.ToDateTime(dateTime);            Console.WriteLine("Year: {0}, Month: {1}, Day: {2}, Hour: {3}, Minute: {4}, Second: {5}, Millisecond: {6}",                              dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond);            // Specify exactly how to interpret the string.            IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);            // Alternate choice: If the string has been input by an end user, you might              // want to format it according to the current culture:             // IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;            DateTime dt2 = DateTime.Parse(dateTime, culture, System.Globalization.DateTimeStyles.AssumeLocal);            Console.WriteLine("Year: {0}, Month: {1}, Day: {2}, Hour: {3}, Minute: {4}, Second: {5}, Millisecond: {6}",                              dt2.Year, dt2.Month, dt2.Day, dt2.Hour, dt2.Minute, dt2.Second, dt2.Millisecond
```

/* Output (assuming first culture is en-US and second is fr-FR):

Year: 2008, Month: 1, Day: 8, Hour: 14, Minute: 50, Second: 50, Millisecond: 420

Year: 2008, Month: 8, Day: 1, Hour: 14, Minute: 50, Second: 50, Millisecond: 420

Press any key to continue . . .

*/


---

Original Source: https://www.mindstick.com/forum/1735/convert-a-string-to-a-date-in-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
