Date Comparison Object
January 14, 2009 – 11:29 amI needed to be able to compare two dates. Since Flex 3 (ActionScript 3) does not have a date compare function I used google and found this post: http://userflex.wordpress.com/2008/09/11/as3-date-compare/. It is a great function and seems to work just fine.
Since there is the potential to use this in more than one place in my application I changed it to a class. Hope this helps someone out there.
package
{
public class dateCompare
{
private var m_result:Number;
public function dateCompare(date1:Date, date2:Date):void
{
var date1Timestamp:Number = date1.getTime();
var date2Timestamp:Number = date2.getTime();
m_result = -1;
if (date1Timestamp == date2Timestamp)
{
m_result = 0;
}
else if (date1Timestamp > date2Timestamp)
{
m_result = 1;
}
}
public function get result():Number
{
return m_result;
}
}
}
You must be logged in to post a comment.