Date Util Functiions

Utility functions to find First Day of a month, Relative Date information like “Today”, “Yesterday”

public static function getFirstDayofMonth(fullyear:uint,month:uint):uint
var tmp:Date = new Date(fullyear,month,1);
return tmp.getDay();

public static function isLeapYear( fullyear:uint ):Boolean
var flag:Boolean = false;
if(((fullyear%4==0) && (fullyear%100!=0)) || (fullyear%400==0)) flag = true;
return flag;

public static function getWeekName( index:uint , type:uint=0 ):String
var week:Array;
else if(type==1) week = [“SUN”,”MON”,”TUE”,”WED”,”THU”,”FRI”,”SAT”];
else week = [“Sun”,”Mon”,”Tue”,”Wed”,”Thu”,”Fri”,”Sat”];
return week[index];

public static function getMonthName( index:uint , type:uint=0 ):String
var month:Array;
else if(type==1) month = [“jan”,”feb”,”mar”,”apr”,”may”,”jun”,”jul”,”aug”,”sep”,”oct”,”nov”,”dec”];
else month = [“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”];
return month[index];

public static function getRelativeDateName( date:Date, type:uint=0 ):String
var d1:Date = new Date();
d1 = new Date(d1.getFullYear(),d1.getMonth(),d1.getDate());
var d2:Date = new Date(date.getFullYear(),date.getMonth(),date.getDate());
if(d11000*60*60*24*7) return “”;
if(type>8||isNaN(type)) type = 0;
var list:Array;
switch(type) {
case 0: case 3:
list = [“TODAY”,”YESTERDAY”]; break;
case 1: case 4:
list = [“Today”,”Yesterday”]; break;
case 2: case 5:
list = [“today”,”yesterday”]; break;
var diff:int = d1.getDate()-d2.getDate();
if(diff<=1) return list[diff];
return getWeekName( d2.getDay(), type );

  1. Nice code, your blog is great!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: