Adding minutes to a date in VBA

orangehairedboy

Board Regular
Joined
Feb 23, 2003
Messages
159
I'm trying to write a function which takes a date and time and a number of minutes, adds to minutes to the date/time and returns the new date/time.

For example, if I gave it "2/23/04", "22:00" and 150 minutes, it should return "2/24/04 00:30".

Anyone know how to do that?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
OK ...
Code:
Public Function y_OHG(d As Range, h As Range, m As Range)
    y_OHG = d + h / 24 + m / 1440
End Function
y040223h1a.xls
ABCDEF
202/23/20042215002/24/20040030
Sheet4


Dose it help?
 
Upvote 0
And if you want to enter the date, the hours, and the minutes as arguments directly into the function, then you can use ...
Code:
Public Function y_OHG1(d As Date, h As Long, m As Long)
    y_OHG1 = (d + h / 24 + m / 1440)
End Function
y040223h1a.xls
ABCDEF
502/24/20040030
Sheet4
 
Upvote 0
I'm only using VBA...not a worksheet. Here's what I have and it doesn't work:

Code:
Sub test()
    MsgBox y_OHG1("2/23/2004", "23:00", 120)
End Sub
Public Function y_OHG1(d As Date, h As Long, m As Long)
    y_OHG1 = (d + h / 24 + m / 1440)
End Function
 
Upvote 0
Now, THAT'S something I can work with! I was using timeserial, but I never thought about doing now+timeserial.

Good idea...as usual.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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