I trying to determine the max date from an ArrayCollection to be used in a
DateField component.     Below is my code.    But it's not working.   The
return variable sends a random date.

public var ac1:Array;
                        
                        public function getMax(ac:ArrayCollection):void
                        {
                                 ac1 = ac.toArray();
                                var mxm:Date = convertSQLDate(ac1[0].eventDate);
                                for (var i:int=0; i<ac1.length; i++) {
                                        var tempDate:Date = 
convertSQLDate(ac1[i].eventDate);
                                        if (tempDate>mxm) {
                                                mxm = tempDate;
                                        }
                                }
                         MAX_DATE = mxm;
                        }


public static function convertSQLDate(dateString:String):Date
                        {
                                if( dateString == null ) return null;

                                var datePattern : RegExp = 
/(\d{4})-(\d+)-(\d+)( (\d+):(\d+):(\d+))?/;
                                var result : Object = datePattern.exec( 
dateString );
                                
                                if( result[ 4 ] != null ) return new Date( 
result[1], result[2] - 1,
result[3], result[ 5 ], result[ 6 ], result[ 7 ] );
                                else return new Date( result[1], result[2] - 1, 
result[3] );            
                                
                        }


Note: The date in the ArrayCollection is set to String format.



--
View this message in context: 
http://apache-flex-users.2333346.n4.nabble.com/Determining-Maximum-Date-from-Array-tp12434.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Reply via email to