1

I am trying to extract datetime info from

"2012/04/03 10:06:21:611747"

using format

String dateformat = @"yyyy/mm/dd hh:mm:ss:ffffff";

Getting an exception - any help is appreciated.

Full code

 String dateformat = @"yyyy/mm/dd hh:mm:ss:ffffff";
 readonly CultureInfo _provider = CultureInfo.InvariantCulture;
 DateTime dateTime = DateTime.ParseExact(line, dateformat, _provider);
1
  • 2
    Try capital MM for month. What exception are you getting? Commented Apr 11, 2012 at 11:40

5 Answers 5

7

Use MM for months:

 String dateformat = @"yyyy/MM/dd hh:mm:ss:ffffff";
Sign up to request clarification or add additional context in comments.

Comments

5

Your format should be:

yyyy/MM/dd hh:mm:ss:ffffff

You have a lower case m for month which is incorrect.

Have a look at this answer for more info: .Net: DateTime String format

Comments

3

You should use

String dateformat = @"yyyy/MM/dd hh:mm:ss:ffffff";

MM is for month, while mm is for minutes!!

Comments

1

Use

String dateformat = @"yyyy/MM/dd hh:mm:ss:ffffff";  

Use MM for month.
The exception was ocurring due to confusion in interpreting m at two different places.

Comments

1

Replace mm with MM

This link will help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.