tags:

views:

26

answers:

2

I have a car rental application I am writing. I am having some issue. Basically I want a user to pick a date from dateTimePicker2 then dateTimePicker1 I then want to subtract those numbers from eachother and store it in car. I have created a button that will multiple the per day charge then display it in a label but I just having an issue with this part.

carRental = dateTimePicker2 - dateTimePicker1;
+2  A: 

You cannot subtract a datetimepicker instance from another. You need to use the selected values, like this:

var timeSpan = dateTimePicker2.Value - dateTimePicker1.Value;
var rentalDays = timeSpan.Days;
... 
klausbyskov
A: 

Do this:

DateTime dateTime2 = dateTimePicker2.Value;

DateTime dateTime1 = dateTimePicker1.Value;

var carRental = dateTime2 - dateTime1;

DateTimePicker.Value Property at MSDN.

Leniel Macaferi