Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can we Operate on textbox using DateTime???.means
i have two textboxes and i want,(textbox2 - textbox1) gives answer in textbox3 in Time Format in C# windows form,basically i am working on "Time Management System",Have there any Syntax that solve my problem.
i am using textbox and also maskedtextbox..
Posted
Comments
Mohsin Azam 16-Jan-13 13:03pm    
Sorry!Not working.

You must cast the content of your textbox to a DateTime. You can do this with the static method DateTime.Parse().
C#
DateTime date1 = DateTime.Parse(textBox1.Text);
DateTime date2 = DateTime.Parse(textBox2.Text);
TimeSpan date3 = date2 - date1;
textBox3.Text = date3.ToString();


Edit: By the time I hit Submit, Abhinav had already provided an answer.
 
Share this answer
 
v2
Try something like
textBox3 = ((TimeSpan)DateTime.Parse(textBox1).Subtract(DateTime.Parse, textBox2)).Days;
 
Share this answer
 
I recommend using DateTimePickers rather than TextBoxes.
 
Share this answer
 
Comments
Mohsin Azam 16-Jan-13 13:47pm    
PIEBALD,Please give me some tips about this..

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