Solved

# Timespan to Integer conversion

Posted on 2006-07-10
1,710 Views
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

0
Question by:maxgall

LVL 4

Accepted Solution

indu_mk earned 250 total points
Use dateDiff.Days()
0

LVL 85

Expert Comment

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
0

## Featured Post

### Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…