Results 1 to 8 of 8
  1. #1
    halt4814 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    19

    Computing Average of Field of Dates in Days

    I have a query that selects records in a certain date range. One of the fields that it outputs is a date in "MM/DD/YYYY" format. What I want my form to output is the average age of that field, but in "days". I want to use the DAvg function, but it outputs some huge number. Help please!



    The function I used is

    =DAvg("<date field name>","<query name>")

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Can you show sample data of what you are trying to do, along with what you would consider an Average?

  3. #3
    halt4814 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    19
    For example,

    I have a query that outputs Order Number and Date fields.
    The data is...

    1253 10/1/2012
    3245 10/10/2012
    4236 10/20/2012

    What I want to accomplish is getting the average age of all those orders. In this case, it would be 49.67 days because from today (11/29/2012), the first order is 59 days old, the second is 50, and the last is 40 days old. How do I code my vba, so that a textbox on my Access form displays that number.

    I tried =DAvg("<date field name>","<query name>"), but it displays some huge number...

  4. #4
    halt4814 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    19
    The full code I used was

    Textbox15.value = DAvg("<date field name>","<query name>")

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You could look at the dateDiff function to get the number of days since today, then manipulate the result.

    I'm not sure what the Avg you're suggesting actually means --- different Orders, different Orderdates???

  6. #6
    halt4814 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    19
    The avg of the order dates

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    No it isn't the average Order date. I think what you are asking for is the
    Average number of Days of Outstanding Orders

    And I suggest you use the datediff function
    http://www.techonthenet.com/access/f...e/datediff.php


    The arithmetic is : (untested)

    As of today, the average number of days of Outstanding orders =
    Sum (datediff("d","OrderDate","Date")/ (Number of Outstanding Orders)

  8. #8
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    The reason that it is showing a huge number is that a date is stored as a number for example 01/01/1900 is actually stored in the db as 1 or the number of days since 12/31/1899 the date datatype is how the number is displayed. So DAVG(datefield,query) assuming the dates are in 2012 is the average of (365*112)+(number of days since jan 1 this year for the date in your db) as stated you need to use the datediff function to get the number of days between the datefield and todays date. Then use the DAVG on that calculation

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

Similar Threads

  1. Dates before 30 days
    By fabiobarreto10 in forum Queries
    Replies: 7
    Last Post: 04-20-2012, 12:11 PM
  2. Computing an Average
    By ctrapper in forum Queries
    Replies: 12
    Last Post: 12-14-2011, 08:33 AM
  3. Dates & Days Fields
    By djclntn in forum Database Design
    Replies: 5
    Last Post: 10-22-2011, 06:22 PM
  4. Replies: 4
    Last Post: 09-06-2011, 02:20 PM
  5. Select Dates between days and two days ago?
    By rstonehouse in forum Queries
    Replies: 4
    Last Post: 08-18-2010, 02:13 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