DateTimePicker Differences in numbers of days problem

PlayKid

Freshman
Joined
Jun 25, 2005
Messages
38
Dear all,

I am trying to calculate the difference between 2 DateTimePickers' values, and I am unable to calculate the differences in numbers of days, it is fine if they both within the same month, but if the month is changed, the problem arise, it just calculated the differences in day and not the month part.
Can anyone help me with this?

Thank you very much

PlayKid
 
PlayKid said:
Dear all,

I am trying to calculate the difference between 2 DateTimePickers' values, and I am unable to calculate the differences in numbers of days, it is fine if they both within the same month, but if the month is changed, the problem arise, it just calculated the differences in day and not the month part.
Can anyone help me with this?

Thank you very much

PlayKid
TimeSpan ts = DateTime.Now - DateTime.MinValue;
MessageBox.Show(ts.TotalDays.ToString());

or, even simpler:

MessageBox.Show((DateTime.Now - DateTime.MinValue).TotalDays.ToString());
 
Here is my code:
Visual Basic:
    Private Sub DateReturnTP_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateReturnTP.ValueChanged
        Dim Difference As TimeSpan
        Difference = DateReturnTP.Value - DateReturnTP.Value
        DurationText.Text = Difference.TotalDays.ToString
    End Sub

At this line of code:
Visual Basic:
Difference = DateReturnTP.Value - DateReturnTP.Value

The problem arises, it says that Operator "-" not defined for types 'Date' and 'Date'.
 
Last edited by a moderator:
Back
Top