Javascript Max Date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blachca
    New Member
    • Jul 2008
    • 5

    Javascript Max Date

    Hello

    I was wondering if there was a function that I could use that would select the maximum date out of an array of date entries. Could you use the javascript Math.max function and put in a date instead of a number? Just wondering
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    You can use Math.max after converting the date to YYYYMMDD format.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      You could also just use the getTime() method to get a number representation of the Date object.

      Comment

      • blachca
        New Member
        • Jul 2008
        • 5

        #4
        Originally posted by acoder
        You could also just use the getTime() method to get a number representation of the Date object.
        do you think you could give me a sample of what the function would look like?

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Can you show what your array looks like?

          Comment

          • blachca
            New Member
            • Jul 2008
            • 5

            #6
            Originally posted by acoder
            Can you show what your array looks like?
            i dont know what that is

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              To quote you from the first post in this thread:
              Originally posted by blachca
              I was wondering if there was a function that I could use that would select the maximum date out of an array of date entries...
              That's the array I'm talking about. Is it an array of Date objects or an array of strings representing dates?

              Comment

              • blachca
                New Member
                • Jul 2008
                • 5

                #8
                It is an array of strings representing dates

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  So can you give some examples? What format are they in?

                  You can either use the method suggested by hsriat in post #2, convert the strings into Date objects and use getTime() or just compare them using < or >.

                  Comment

                  Working...