ASP.NET C# format textbox to datetime value

I have a property DOB that is of type datetime

newClient.Dob


However I need to display the datetime as a date like 31/07/1955

But currently it displays 31/07/1955 00:00:00

How can I do this so it only displays 31/07/1955 ?
mugseyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
p_davisConnect With a Mentor Commented:
you can use DateTime.Parse(txtDob.Text).ToShortDateString();
0
 
p_davisCommented:
newClient.Dob.ToShortDateString()
0
 
p_davisCommented:
newClient.Dob.ToShortDateString("mmddyyyy")
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mugseyAuthor Commented:
Thanks but I don't have an option to to this on the property DOB that is of type datetime.

The only way I can do it is this

newClient.Dob = Convert.ToDateTime(txtDob.Text).ToShortDateString();

However I get error "cannot convert string to datetime"
0
 
mugseyAuthor Commented:
I tried that but still get string to datetime error
0
 
p_davisCommented:
ok wait, are you just wanting to set the text in the control or are you trying to write it back to the db??

<< I need to display the datetime as a date like 31/07/1955>>
made me think that you just wanted to set a control with this value so

txtDob.Text = newClient.Dob.ToShortDateString("mmddyyyy")

was what i thought you were wanting.
0
 
p_davisCommented:
if you just want to write back to the db the leave off the toshortdatestring();
0
All Courses

From novice to tech pro — start learning today.