Wednesday, March 28, 2007

Convert String To Formatted Date and Time

private void Form1_Load(object sender, System.EventArgs e){
DateTime dt;
string InputDateString = "20070328";
 int iYear =
System.Convert.ToInt32(InputDateString.Substring(0,4));
  int iMonth =
System.Convert.ToInt32(InputDateString.Substring(4,2));
 int iDay =
System.Convert.ToInt32(InputDateString.Substring(6,2));
dt = new DateTime(iYear, iMonth, iDay);
MessageBox.Show(dt.Date.ToString());
MessageBox.Show(dt.Year+" "+dt.Month+", "+dt.Day);
//Change Any Format As You Like It
}



No comments:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.