By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Calculating time passed in a range

P: 1
Hi all,

I've got a project where I need to calculate the time passed between an acceptable range.
For example

E-mail was received at 19:00 and a response was sent at 09:00
The acceptable range is 8am to 6pm so in the scenario it shoudl return 60 mins.

Another example is if the email was received at 16:00 reply was sent on 10:00 am next day it should return 240.

Any thought how to acehive this.

Ive saved the data in variable as timein and timeout
Oct 6 '12 #1
Share this Question
Share on Google+
1 Reply


!NoItAll
100+
P: 296
look at the date class and methods. You need to incorporate the entire date so it takes into account when items cross midnight.
Here's an example of comparing now with another date 3 hours into the future. You can put in the appropriate times that you want.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim Timein As Date = Now
  3. Dim TimeOut As Date = Timein.AddHours(CDbl(3))
  4.  
  5. Dim Diff As Long = TimeOut.Subtract(Timein).TotalHours
  6.  
  7. MsgBox(Diff.ToString)
  8.  
  9.  
Oct 11 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.