You should use DateTime.TryParseExcact
if you know the format, or if not and want to use the system settings DateTime.TryParse
. And to print the date,DateTime.ToString
with the right format in the argument. To get the year, month or day you have DateTime.Year
, DateTime.Month
or DateTime.Day
.
See DateTime Structures in MSDN for additional references.