You must specify the format of the used DateTime value:
String dateTimeFormat = "yyyy";
To show only part of the DateTime value, use the following:
dateTimeValue.ToString(dateTimeFormat);
To read the String value that represents the year in DateTime , use the following:
DateTime.ParseExact(stringValue, dateTimeFormat, CultureInfo.InvariantCulture);
The DateTime.ParseExact (String, String, IFormatProvider) method converts the specified string representation of the date and time into its DateTime equivalent using the specified format and format information for a specific culture. The format of the string representation must exactly match the specified format.
The DateTime.ToString method converts the value of the current DateTime object to its equivalent string representation.
Akram Shahda
source share