Steven Spielberg
Steven Spielberg

Reputation:

how to make this date valid in c#

i want to make my date valid 16/10/2010

if i parse compiler give me error at runtime. how i can parse it.

it is formated as Day/Month/Year

Upvotes: 0

Views: 357

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503954

You'd parse it with something like:

DateTime dt = DateTime.ParseExact(text, "dd/MM/yyyy",
                                  CultureInfo.InvariantCulture);

Use DateTime.TryParseExact if this is user input which may well be invalid without it representing a bug in your code.

Upvotes: 5

Related Questions