Solved

VBScript - Subtracting two Times and Outputing # Minutes

Posted on 2000-03-14
4
846 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now