Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi All, Firs I will be grateful

Status
Not open for further replies.

Ali Abbas

IS-IT--Management
Jun 14, 2019
2
0
0
GB
Hi All,

Firs I will be grateful if you can help me. I need your help in a VBA code. I need to find differences in dates and times. I want to find the date and time differences of columns C and D and the answer to be in column E. I want the rows fixable in a loop. The code does the calculations to find the differences in all rows. And I am attaching an example in an excel file to make it clear. Thanks
 
 https://files.engineering.com/getfile.aspx?folder=e3ad781c-26c6-4b90-8fcc-6b952d38034e&file=Habeeb_1.xlsm
The first challenge I I think is that your start date, though earlier than your end date, may have a later time then the end date, so if you don't do it right, you will get negative hours. In the sample code below, I am giving two dates, June 3 and June 9, clearly 6 days apart, but the way my cod sees it, it's really 5 days and (with the time I provide) 20.83 hours. Hope this works for you.

ChaZ

Code:
Function DoIt()
    Dim A As Date
    Dim B As Date
    Dim Minutes As Long
    Dim Result As String
    A = #6/3/2019 1:04:00 PM#
    B = #6/9/2019 9:54:00 AM#
    Minutes = DateDiff("n", A, B)
    Result = Int(Minutes / 1440) & " Days, "
    Result = Result & Format((Minutes - Int(Minutes / 1440) * 1440) / 60, "Standard") & " Hours"
    MsgBox Result
End Function

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That DonÆt.

 
This would seem to be a Excel VBA question, rather than anything to do with Access. And I see you have already asked this in the VBA forum, thread707-1795353, so probably best to follow that thread (where Skip seems to have provided what might be considered the best practice answer for this - using Excel's capabilities rather than VBA) rather than reposting the same question everywhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top