work out number of minutes between two date plus times in VBA

th081

Board Regular
Joined
Mar 26, 2006
Messages
98
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Can someone help me with how to work out the number of minutes between two dates and time in VBA. I am using DateDiff but it seems to truncate the time part and ignore it.

I have two arrays one starts at 01/04/2021 with the next value increasing by 30mins so being 01/04/2021 00:30 etc, the second array has a imported spreadsheet date and time, both are declared as variants because for the second one i am assigning the whole range to the array.

This is my sub:

Sub Declaration_Compare2(x As Integer, y As Integer)
p = x
L = y
Dim nMins As Long
Dim dt1 As Date
Dim dt2 As Date



dt1 = DateValue(Effective_DateTime_F(p, 1))
dt2 = DateValue(MyArraydatestart(L))

nMins = DateDiff("n", dt1, dt2)



End Sub

the Effective_DateTime_F(p, 1) value is 31/03/21 22:59:00 as imported from the spreadsheet
the MyArraydatestart(L) value is 01/04/21 as held in the array

i was expecting nMins to be the difference in minutes between the date and times but it gives 1440 i.e just one day, it does not take the time into account. Can i get it to take the time into account or is there another function to use?

Regards

Taz
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Is there a time value associated with your 2nd date or will it always be midnight (0:00)?
 
Upvote 0
Hi Rick,

There is a time associated with the second date, so the next value in that array is 01/04/21 00:30
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top