how can i assign only year say 2011 in a datetime variable in c#

Viewed 32917

I have a asp Text box as where the user will fill only a year value, For this value I have Datetime type Property in c# application and Date type column in DB. So I want to convert that txtYear.Text to DateTime But it will only hold and/or show the year. Please help me in this situation.

8 Answers

That is how I did and it worked.

string format = "yyyy";
        var CurrentYear = DateTime.Now.ToString(format);
Related