Results 1 to 8 of 8
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    Max and Min Determination for Dates

    Hi,

    I'd like to take two date values within a query and determine the max and/or min of each, within a new field.

    I am not sure how to do this.

    I have tried DMin and DMax functions, but they give me "#ERROR" as a response in my query.



    Does anyone know a useful method to determine min and max for dates?

    Thanks

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Please post your DMin, DMax formula attempts that are giving your errors.

    If you describe your data layout, we can probably help you come up with what you need.

  3. #3
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    Here is an example of what it is I am doing and the Error that I am getting. There is no relationship established between the tables, but that's fine for the purposes of what it is I am trying to accomplish.

    Click image for larger version. 

Name:	Example.jpg 
Views:	14 
Size:	98.7 KB 
ID:	19075

    Click image for larger version. 

Name:	Example2.jpg 
Views:	14 
Size:	146.0 KB 
ID:	19076

  4. #4
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    I realize that I am probably not using the DMin and DMax function correctly.

    What I need to do either way is determine the Max or the Min as such:

    MAX(Info.StartDate, Months.StartDate) and MIN(Info.EndDate, Months.EndDate)


    Is there a good way to do this?

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Your functions aren't structured properly. See here: http://www.techonthenet.com/access/f...omain/dmax.php

    Note that the second argument is just your object (table/query) name, no field attached to it.

  6. #6
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    I'm not convinced that the way the DMax and DMin as well as Max and Min functions work will supply the result I need.

    I am looking for a simple mathematical Min(x,y) or Max(x,y) determination between two field values. I am not trying to find a particular Max or Min of a field as part of an aggregate function.

    SOLUTION:

    I managed a work-around.

    Max(x,y) = IIF( x > y, x, y)

    You need to convert from Date to Integer using the function CLng. Then you need to convert back to Date. The final output is as such...

    Format(IIf(CLng([Info]![Start_Date])>CLng([Months]![Start_Date]),CLng([Info]![Start_Date]),CLng([Months]![Start_Date])),"m/dd/yyyy")

  7. #7
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    I think you need to use IIF(Date1>Date2,Date1,Date2) in your query instead of DMax. As pointed out, DMax is to find the MAX value from a table/query based on a criteria.
    Edit : I left the window open for some time and when I replied, you already had the answer I was suggesting.

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I am looking for a simple mathematical Min(x,y) or Max(x,y) determination between two field values. I am not trying to find a particular Max or Min of a field as part of an aggregate function.
    Well, that certainly is much different from your original question.
    Glad you figured it out.

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

Similar Threads

  1. Replies: 8
    Last Post: 12-02-2013, 03:46 PM
  2. List Dates between Start and Finish Dates
    By Buddus in forum Queries
    Replies: 1
    Last Post: 07-26-2013, 01:58 PM
  3. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  4. Replies: 10
    Last Post: 11-16-2011, 10:58 AM
  5. Mixed dates - show only complete dates?
    By weeblesue in forum Queries
    Replies: 3
    Last Post: 10-27-2010, 02:15 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