Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 897
  • Last Modified:

VBScript - Subtracting two Times and Outputing # Minutes

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
ubsjmg
Asked:
ubsjmg
  • 2
1 Solution
 
ndbCommented:
Result = DateDiff(DateTime1, DateTime2, "m")
0
 
ivancCommented:
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
 
damienmCommented:
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
 
ndbCommented:
Oops ... indeed ... thanx damien.
After all that VB code today I can c them flying ;0)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now