P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Date
:
get dates in format specified and for a specified period of time from a certain period:D
author:
SiliconMind
[+]
,
Submitted: 05.07.04 5p
function returnDays(dateObj, dayNum, dayFormat, monthFormat) { if (typeof dayNum != "number" or dayNum==0) { trace("ERROR - no number sumbitted"); return; } //************************************************************************************* //Full Respect //All rights reserved sxdesign //@ http://proto.layer51.com/d.aspx?f=743 Date.prototype.getDateOffset = function(offset) { var retDate = new Date(this); retDate.setTime(retDate.getTime()+offset*86400000); // 86400000 represents a number of milliseconds each day haves return retDate; }; //************************************************************************************* if (dateObj == null) { nowDate = new Date(); } else { nowDate = dateObj; } //string data*************************************************************************** var shortDayArr:Array = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); var fullDayArr:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); var shortMonthArr:Array = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); var fullMonthArr:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); //************************************************************************************* var daysObjArr:Array = new Array(); var daysLabelsArr:Array = new Array(); //determines which direction we're going if(dayNum>0) { dir=1; }else if(dayNum<0) { dir=-1; } for (i=1; i<=Math.abs(dayNum); i++) { daysObjArr.push(nowDate.getDateOffset(dir*i)); } for (a=0; a<daysObjArr.length; a++) { if (dayFormat != null and monthFormat != null) { daysLabelsArr.push(((dayFormat == true) ? fullDayArr[daysObjArr[a].getDay()] : shortDayArr[daysObjArr[a].getDay()])+", "+((monthFormat == true) ? fullMonthArr[daysObjArr[a].getMonth()] : shortMonthArr[daysObjArr[a].getMonth()])+" "+daysObjArr[a].getDate()); } else if (dayFormat == null and monthFormat != null) { daysLabelsArr.push(((monthFormat == true) ? fullMonthArr[daysObjArr[a].getMonth()] : shortMonthArr[daysObjArr[a].getMonth()])+" "+daysObjArr[a].getDate()); } else if (dayFormat != null and monthFormat == null) { daysLabelsArr.push(((dayFormat == true) ? fullDayArr[daysObjArr[a].getDay()] : shortDayArr[daysObjArr[a].getDay()])+", "+" "+daysObjArr[a].getDate()); } trace(daysLabelsArr[a]); } return daysLabelsArr }
usage
the function returns a string array with the days as requested, ************************************************************************** Arguments: >dateObj = a date object which will be taken as a reference or null for today >dayNum = number of days to return, can be positive or negative >dayFormat = 1 for full day name, 0 - short name, null - no day name >monthFormat = 1 for full month name, 0 - short name, null - no month name ************************************************************************** Example usage [code] myDaysArry = returnDays(null, -5, 1, 0) //null for today as reference //-5 for five days back from today, i.e. yesterday, the day before yesterday etc... //1 for full day name display //0 for short month name [/code] return something like Thursday, May 6 Wednesday, May 5 Tuesday, May 4 Monday, May 3 Sunday, May 2
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@