Solved

Timespan to Integer conversion

Posted on 2006-07-10
2
1,761 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
ID: 17072081
Use dateDiff.Days()
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17073295
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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