Results 1 to 6 of 6
  1. #1
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72

    How to get Total Time difference between two text fields in _ _:_ _ time format

    Hi,

    i have two text fields called start and end time with and input mask which makes the format _ _ : _ _, ie. 12:10. The time goes up to 24:00 (using military time). I want a third text field called total duration to be the difference between the end time and start in minutes. Can someone help me achieve this, thanks.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Are you familiar with VBA? I suspect you are going to need to do some data type conversion. What data type is the field that stores the time values?

  3. #3
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72
    I am familiar with vba. The data types are text. If you simply say the procedure i will be able to code it.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You will want to declare a couple variables of type Date. Initialize them using the fields that have the text that represent the time.

    Use the DateDiff function to calculate the difference between the two variables.

    I think that should do it. When you add text to a date field or initialize a date variable that represents the time only, Access will add a default date to complete the missing info. Make sure you are making provisions for understanding AM and PM. I believe Access will assume 24hr clock if you do not include the AM or PM syntax. Use the immediate window and or step debug to verify variable values as they are initialized.

    EDIT: You may have to employ the Left() or Mid() function to add the semicolon to the text before initializing the Date variables.

  5. #5
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72
    Thanks,

    i used the DateDiff Function with the following code and it worked.

    Code:
    text111 = DateDiff("n", [Start], [End])
    Start and End were date/time fields and the difference in minutes (n signifies minutes) goes into text box "text111".

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Cool......

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

Similar Threads

  1. Total query with date/time fields
    By Ruegen in forum Queries
    Replies: 8
    Last Post: 09-03-2013, 05:32 PM
  2. Replies: 8
    Last Post: 08-24-2012, 01:54 AM
  3. Replies: 5
    Last Post: 06-23-2012, 04:30 PM
  4. Replies: 1
    Last Post: 08-07-2011, 07:58 AM
  5. Time difference
    By jguidry in forum Programming
    Replies: 1
    Last Post: 11-15-2008, 12:41 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