Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005

    Unanswered: time calculation

    I would like to know how to calculate very simply the difference between two fields (StartTime and EndTime). Both of these are date/time fields and I was trying to use a third field text field with a formula like [EndTime]-[StartTime], but I get the right number of hours but it has PM or AM After it. I just want the number of hours.

    Second problem when I enter my starttime or endtime I must enter it in a 24 hour format, is there a way to be able to enter the time 12 hour format and maybe have another field for PM or AM?

    Thanks for your help...


  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    have you tried adjusting the forma3tting of the control field(s)
    Access makes assumptions about the default formatting of a control. Usually you can enter informatiopn in any style you wish, providing the underlying datatype 'understands' that format.

    So I would expect answer to question one is to change the display format, failing that you might have to do some manual reformatting
    strtimeelapsed=hour(dattimeelpased) & ":" & minute( ....etc

    As reagrds to entering data in AM/PM format, then unless there is a standard format code you are on your own, you may need to enter the time as a string & split using a fucntion call that parses the separate elements

  3. #3
    Join Date
    Dec 2002
    Préverenges, Switzerland
    sometimes it's a joy to work in a 24-hour clock part of the world!

    anyhow, here's one way to do what you want in the second question:

    a textbox myInput set to short time 24 hour clock (trust me!)
    and some way for the user to signal he wants AM or PM (symbolised below with variable userWantsAM)

    If myInput > #12:00:00 PM# Then
    MsgBox "Valid time range is 00:00 to 12:00"
    If userWantsAM Then
    outputDate = CDate(myInput)
    outputDate = CDate(myInput) + 0.5
    End If
    End If

    currently using SS 2008R2

  4. #4
    Join Date
    Jan 2005
    Thanks for the help. I changed the formatting and it solves the problem with the calculation. I will work on the AM and PM part.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts