Link to home
Start Free TrialLog in
Avatar of maxgall
maxgall

asked on

Timespan to Integer conversion

I am having problems converting the difference of two dates into an integer from double. I have the following code:
Dim date1, date2 as date
Dim dateDiff as timespan
Dim i as integer = 0
date1 = "20/07/2006"
date2 = "05/08/2006"

dateDiff = date2.subtract(date1)

Dim intDateDiff as integer = cType(dateDiff, integer)  ' also tried  cInt(datediff)

Then I want to use intDateDiff in some code like:

For i = 0 to intDateDiff
'code here
Next

I get the following error converting timespan to integer
Error      3      Value of type 'System.TimeSpan' cannot be converted to 'Integer'.

Any ideas how to get an integer from two dates.

thanks
Max

ASKER CERTIFIED SOLUTION
Avatar of indu_mk
indu_mk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Tomlinson
What do you want to measure between these two dates?...

The TimeSpan class (which you have in "dateDiff") gives you many options such as days, hours, minutes, seconds, milliseconds, etc....
http://msdn2.microsoft.com/en-us/library/system.timespan_members.aspx