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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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