Solved

Timespan to Integer conversion

Posted on 2006-07-10
2
1,710 Views
Last Modified: 2012-06-27
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
Comment
Question by:maxgall
2 Comments
 
LVL 4

Accepted Solution

by:
indu_mk earned 250 total points
Comment Utility
Use dateDiff.Days()
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now