Click here to Skip to main content
16,016,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a String strTemp = "2012". So how can i convert that string to Datetime?
who can help me :). Thanks
Posted

1 solution

This code here is definitely working:
C#
string strTemp = "2012";
DateTime time = DateTime.ParseExact(strTemp, "yyyy", CultureInfo.InvariantCulture);
MessageBox.Show(time.ToString());

It gives an output of: "01.01.2012 00:00:00"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900