Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
i am having trouble in subtracting time in format dd/mm/yy from 2 combo box,if any 1 have a solution plz let me know...thanks
Posted

Your question is not clear enough. For subtracting datetime values please check the below examples.
C#
DateTime dt = new DateTime();
dt.AddDays(-1);  //Subtract one day
dt.AddHours(-1); //Subtract one hour
dt.AddMinutes(-1); //Subtract one minute
dt.AddMonths(-1); //Subtract one month

-or-
C#
DateTime value1 = new DateTime(2011, 12, 20);
DateTime value2 = new DateTime(2011, 1, 1);
TimeSpan span = newYears.Subtract(value1);
 
Share this answer
 
v2
DateTime has its own property which is ToShortDate which exclude time from date for you below is an example.

DropDownList dd = new DropDownList();
dd.Items.Add(new ListItem(DateTime.Now.ToShortDateString()));

I think this will solve your issue
 
Share this answer
 
First thing to do: convert the two times to a DateTime - use DateTime.Parse or DateTime.TryParse:
C#
DataTime dt = DateTime.Parse("24/02/10");
You can then subtract one DataTime from another to yield a TimeSpan.

The alternative is not to use a combo box, but a DateTimePicker - which makes the job easier as it won't let the user enter a bad date.
 
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