Results 1 to 5 of 5
  1. #1
    rywello is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2018
    Posts
    14

    Date Diff to calculate hours.

    I am using the below code to get the hours worked between the TimeIn and TimeOut and it works fine but if the shift starts in the PM and ends in the AM, it does not recognize the next day. For example if the start time is 8PM and ends at 1AM it gives me a total of 19 hours. It is takes the AM end time as the start time. Those fields are a date/time field. Any help would be appreciated. Thanks!



    Total: (Abs(DateDiff("n",[TimeIn],[TimeOut])/60)))

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    The timeIn/out fields sshould hold BOTH date and time for this very reason.

    5\1\2018 4:00 pm
    you don't want date in 1 field and time in another.

  3. #3
    rywello is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2018
    Posts
    14
    Both of the fields are date/time with the General Date format but only the time shows.

  4. #4
    Join Date
    Apr 2017
    Posts
    1,679
    Format one of your datetime fields (TimeIn/TimeOut) as double temporarily. When the field values are <1, then you have only time part without date info. It depends on regional settings, but with some formats only time part is saved to field. I'm not entirely sure, but I have the feeling that when I last time encountered such behavior, I tried to use General Time format. Use Custom format instead.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Possibly your dates are not in US format? this ought to work
    Code:
    Abs(DateDiff("n",#05/30/2018 08:00:00 pm#,#05/31/2018 01:00:00 am#)/60)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How Calculate Hours By week
    By christ2000 in forum Access
    Replies: 2
    Last Post: 03-12-2018, 08:58 AM
  2. Replies: 3
    Last Post: 03-02-2016, 09:39 AM
  3. how to calculate hours
    By ultra5219 in forum Queries
    Replies: 2
    Last Post: 05-23-2013, 04:22 PM
  4. Replies: 1
    Last Post: 08-08-2012, 01:42 PM
  5. Replies: 4
    Last Post: 08-06-2012, 10:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums