Results 1 to 3 of 3

Thread: Average Date and Time from a table[resolved]

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    5

    Average Date and Time from a table[resolved]

    Im having some problems with a Access Program Im writing. It consists of 4 fields in a table [ID][LogDate][logintime][logouttime]

    This program is for a login system for a computer lab. My problem is that I need to take the average minutes people are logged in, and use that as a running average. I then need to take than running average and use it to fill in any blank logout time fields at the end of the day.

    My main question is how to I take datedifference[logintime][logouttime] and capture it into a variable for later use.

    THanks.
    Last edited by ustenmacduff; Apr 18th, 2005 at 11:18 PM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Average Date and Time from a table

    VB Code:
    1. 'replace a and b with your dates:
    2. myVar = DateDiff("n", a, b)
    "n" means minutes, it may be better to use "s" (seconds), and round it as you see fit.


    I don't really agree with the idea of setting logouttime to an averaged value, but I can't think of a better alternative if you need to have a value (I would personally leave it null, as it is more accurate, and you can see who doesnt log out properly ).

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    5

    Re: Average Date and Time from a table

    I finally got it to work.

    Heres what I did:

    VB Code:
    1. Dim rs As DAO.Recordset 'Recordset for query
    2. Dim strSQL As String 'Holds SQL
    3. Dim avgMin As Integer 'Hold Minutes
    4. strSQL = "SELECT AVG(DateDiff('n',[TimeIn],[TimeOut])) AS AverageMinutes FROM StudentLog WHERE TimeIn Is Not Null And TimeOut Is Not Null"
    5. Set rs = CurrentDb.OpenRecordset(strSQL)
    6. avgMin = rs.Fields("[AverageMinutes]")
    7.  
    8. strSQL = "UPDATE StudentLog SET TimeOut = (DATEADD('n'," & avgMin & ",[TimeIn]))  WHERE TimeOut Is Null"
    9. DoCmd.RunSQL (strSQL)
    Last edited by ustenmacduff; Apr 18th, 2005 at 11:17 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
  •  



Click Here to Expand Forum to Full Width