-1

how to convert string year to DateTime format ?

my code :

// click button
string a = "2014";
DateTime b = DateTime.Parse(a);
MessageBox.Show(b.ToString());
marshall
  • 74
  • 1
  • 7

1 Answers1

3

You can try something like this

var year = int.Parse("2014");   
DateTime dateTime = new DateTime(year, 1, 1);
Console.WriteLine(dateTime.ToString());   
MethodMan
  • 18,625
  • 6
  • 34
  • 52
BRAHIM Kamel
  • 13,492
  • 1
  • 36
  • 47