Multiple Date field and Obtain the Maximun Date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ElTipo
    New Member
    • Jul 2007
    • 36

    Multiple Date field and Obtain the Maximun Date

    Hello People!

    I have 3 fields dates. Example: Date1, Date2 and Date3. I don't know how obtain in this 3 fields the greater date.

    Ex:

    If Date1 = 01/01/08 and Date2 = 01/02/08 and Date3 = 01/03/08

    then the field show [Date3].

    These fields are for a data entry and the query I made most show for these fields the maximun date field.

    Any One!!!

    Thanks!!
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    This should properly be done with a Bubble Sort, but I haven't done one in decades and am too lazy to figure it out! Sorry! But with only three elements to sort, it's simple to do with four If statements. Sorry!
    Code:
    If Me.Date1 > Me.Date2 And Me.Date1 > Me.Date3 Then Me.GreaterDate  = Me.Date1
    If Me.Date2 > Me.Date1 And Me.Date2 > Me.Date3 Then Me.GreaterDate  = Me.Date2
    If Me.Date3 > Me.Date1 And Me.Date3 > Me.Date2 Then Me.GreaterDate  = Me.Date3
    If Me.Date1 = Me.Date2 And Me.Date2 = Me.Date3 Then Me.GreaterDate  = Me.Date1
    Linq ;0)>

    Comment

    • ElTipo
      New Member
      • Jul 2007
      • 36

      #3
      Originally posted by missinglinq
      This should properly be done with a Bubble Sort, but I haven't done one in decades and am too lazy to figure it out! Sorry! But with only three elements to sort, it's simple to do with four If statements. Sorry!
      Code:
      If Me.Date1 > Me.Date2 And Me.Date1 > Me.Date3 Then Me.GreaterDate  = Me.Date1
      If Me.Date2 > Me.Date1 And Me.Date2 > Me.Date3 Then Me.GreaterDate  = Me.Date2
      If Me.Date3 > Me.Date1 And Me.Date3 > Me.Date2 Then Me.GreaterDate  = Me.Date3
      If Me.Date1 = Me.Date2 And Me.Date2 = Me.Date3 Then Me.GreaterDate  = Me.Date1
      Linq ;0)>
      Is Posible to create in the Query Column?

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        Try :
        Code:
        Latest:IIf([Date1]>[Date2],IIf([Date1]>[Date3],[Date1],[Date3]),IIf([Date2]>[Date3],[Date2],[Date3]))

        Comment

        • ElTipo
          New Member
          • Jul 2007
          • 36

          #5
          So, it's possible to put these fields in one in a query and show the greater date?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32661

            #6
            Well, yes.

            The illustration is in my previous post :S

            Comment

            Working...