tony
tony

Reputation: 853

Populate DateTime from a string

I would like to populate a DateTime structure from a string, but it is not working: This is the format I have: i.e.: "6/4/09 11:10 AM"

This is what I am using but it is not working DateTime dttm = DateTime.ParseExact(dttmString, "d/m/yy H:mm tt", format);

Any idea? Thanks

Tony

Upvotes: 0

Views: 683

Answers (3)

rocka
rocka

Reputation: 162

try using a capital 'M' for month.

Upvotes: 0

Darthg8r
Darthg8r

Reputation: 12675

It's your month. Month is "M". "m" is minutes. "H" is 24 hour time. Here's a reference page for datetime.parseextact and datetime.tostring format strings. http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm

Upvotes: 3

csharptest.net
csharptest.net

Reputation: 64218

use "d/M/yy h:mm tt", format);

Change 'm' to 'M' for month and change 'H' to 'h' for hour.

Upvotes: 1

Related Questions