Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert.ToDateTime()

Status
Not open for further replies.

cathiec

Programmer
Oct 21, 2003
139
IE
The textbox TextBox1 converts what the user types into DateTime format. This is fine but the date that the user enters also has the hours, minutes and seconds appended onto the end of the date. I just want the date in the format dd/mm/yyyy and not in the format dd/mm/yyyy 00:00:00.

DateTime theDate = Convert.ToDateTime(TextBox1.Text);





 
Use string.Format () :
string sDate;
try
{
sDate = string.Format("{0:dd/mm/yyyy}", textBox1.Text);
// conversion successfull
}
catch (Exception e)
{
// invalid date string
throw new Exception (e.GetType() + e.Message;
}
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top