Solved

VBScript - Subtracting two Times and Outputing # Minutes

Posted on 2000-03-14
4
868 Views
Last Modified: 2012-06-27
I need a function to subtract two date and times to come up with the number of minutes.  I am new to vbscript how can this be done?
0
Comment
Question by:ubsjmg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
ndb earned 100 total points
ID: 2616340
Result = DateDiff(DateTime1, DateTime2, "m")
0
 
LVL 3

Expert Comment

by:ivanc
ID: 2616355
ubsima
Convert all the date parameters to integers and substract like integers to make comparisons

Dim Release as Date

toDay = CInt(Format(Now, "dd"))
thsMth = CInt(Format(Now, "mm"))
thsYr = CInt(Format(Now, "yyyy"))
RelDay = CInt(Format(Release, "dd"))
RelMth = CInt(Format(Release, "mm"))
RelYr = CInt(Format(Release, "yyyy"))

Diffyr = Relyr - thsyr
Diffmth = RelMth - thsMth
DiffDay = RelDay - toDay

Hope this helps
Ivan
0
 
LVL 2

Expert Comment

by:damienm
ID: 2616406
ndb I think you have the function the wrong way around

This function should work

MsgBox DateDiff("n", Date1, Date2)
'n is minutes

e.g

Private Sub Command1_Click()
MsgBox DateDiff("n", "1-Jan-00 1 am", "2-Jan-00 2 am")
End Sub

will give msgbox 2500
0
 
LVL 1

Expert Comment

by:ndb
ID: 2616449
Oops ... indeed ... thanx damien.
After all that VB code today I can c them flying ;0)
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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