Results 1 to 6 of 6
  1. #1
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44

    Counting minutes formula - problem with after midnight -

    Hi guys. I have a problem with formula when it comes down to this situation shown on the picture.


    When my first entered time is before midnight, and second is after, it won't work.
    I have created a calculated field with this expression :
    Code:
    (Hour([End_time]-[Start_time])*60)+Minute([End_time]-[Start_time])
    It is supossed to calculate minutes from two times, start and end, and it works just fine,
    until it comes up to a situation on the picture. Also, the start and end time are "Date/Time" type of data in my table.

    Can you help me fix this?

    Click image for larger version. 

Name:	Capture.JPG 
Views:	22 
Size:	18.3 KB 
ID:	43571

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    I think your problem is because Access doesn't know that 0:15 is a time in the next day.
    Allen Browne has some advice on time calculation: http://allenbrowne.com/casu-13.html
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by Bob Fitz View Post
    I think your problem is because Access doesn't know that 0:15 is a time in the next day.
    Allen Browne has some advice on time calculation: http://allenbrowne.com/casu-13.html
    Hi, thank you for you help, although it didn't work for me, I have found a solution.
    I am posting it here, so if anybody have the same problem, here is the solution that calculates the minutes just fine

    Code:
    (Hour([Start_time]-1-[End_time])*60)+Minute([Start_time]-1-[End_time])
    Cheers

  4. #4
    CarlettoFed is online now Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    274

    Risposta

    Don't say you've solved it, look at this example when the difference between days is greater than 1.

    Click image for larger version. 

Name:	Query.png 
Views:	17 
Size:	9.3 KB 
ID:	43589

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Why not just include the date portion and then datediff("n",starttime,endtime) ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Thank you all for your advices and help

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

Similar Threads

  1. Replies: 7
    Last Post: 06-02-2015, 09:36 AM
  2. Replies: 4
    Last Post: 04-04-2015, 03:28 AM
  3. Cross-Midnight Shift Problem
    By daniel.ru92 in forum Queries
    Replies: 10
    Last Post: 05-06-2013, 11:15 AM
  4. Formula for counting shifts
    By Huddle in forum Access
    Replies: 4
    Last Post: 05-10-2012, 02:56 PM
  5. Replies: 3
    Last Post: 09-01-2011, 11:07 PM

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