Solved

Timespan to Integer conversion

Posted on 2006-07-10
2
1,786 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 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