Ah, didn't see abdul's post. I would use his approach instead. -lin
-----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Lin Lin Sent: Friday, April 22, 2005 2:06 PM To: [email protected] Subject: RE: [flexcoders] Re: DATE Function in Flex Hi, I just made a testing sample for something similar to the DateAdd function. This is only for increment 1 day, but you can easily modify that to add more feature. The days param in mynewDate(days) is for how many days you want to add to the giving date. This may not be the best way to doing this, is just one way of doing it. <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" > <mx:Script><![CDATA[ import mx.formatters.DateFormatter; var dp=new Array(); var newdate,nextday; var today,todayDate,todayMonth,todayYear,lastday,newday; var odd=new Array(1,3,5,7,8,10,12); //for month end a 31 var even=new Array(2,4,6,9,11); //for month end a 30 function intday(input) { var today= DateFormatter.parseDateString(input); //var today= DateFormatter.parseDateString(inputDate); todayDate = today.getDate(); todayMonth = (today.getMonth()+1); todayYear = today.getFullYear(); } function leapday() { var lyear = todayYear/4; if( lyear == Math.floor(lyear)){ var l400 = todayYear/400; if (l400==Math.floor(l400)){ var leap = "true"; } } leap?lastday=29:lastday=28; } function mynewDate(days){ if (0<todayMonth<=12){ lb1.text =" "; if (todayMonth ==4 || todayMonth ==6 ||todayMonth ==9 ||todayMonth==11) {lastday=30;} else if (todayMonth == 2){ leapday(); } else {lastday=31;} lb.text = "lastday="+lastday+" "; for(var i=0;i<days;i++){ newday = todayDate +1; if (todayDate == lastday){ todayDate = (newday-lastday); nextday= ((todayMonth+1)+"/"+todayDate); todayMonth = todayMonth+1; }else if(todayDate <lastday) { nextday= (todayMonth+"/"+newday); todayDate=newday; } else if (todayDate > lastday){ alert("no date greater than " + lastday + " for this month","error",mx.controls.Alert.OK); } lb.text+="todayMonth="+todayMonth+" "; lb1.text +=nextday+" "; dp.puah(nextday); } } else { alert("invalid month","error",mx.controls.Alert.OK); } } ]]></mx:Script> <mx:Label id="lb" /> <mx:Label id="lb1" /> <mx:TextInput id="tx" enter="intday(tx.text),mynewDate(5)" ></mx:TextInput> <mx:DateChooser id="dateFieldEnabled" selectedDate="{DateFormatter.parseDateString(tx.text)}" enabled="true"/> </mx:Application> -lin -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of reubenbrown13 Sent: Friday, April 22, 2005 10:34 AM To: [email protected] Subject: [flexcoders] Re: DATE Function in Flex For those familiar with coldfusion, this function might be of use. It is called DateAdd and takes 3 parameters just like the CF version. It can be extended for other date parts, but this code snipit is only for modifying the year of a date passed. I have used both for passing dates to webservice calls and they work perfectly. I hope it helps. function DateAdd(datepart, value, tmpDate):Date{ // tmpDate is a date in the YYYY,MM,DD,HH,MM,SS format if (tmpDate == ''){tmpDate = Now();} var new_date:Date; var tmpValue:Number; if (datepart == 'yyyy'){ tmpValue = tmpDate.getFullYear() + value; new_date = new Date(tmpValue,tmpDate.getMonth(),tmpDate.getDate(),tmpDate.getHours(),tm pDate.getMinutes(),tmpDate.getSeconds(),tmpDate.getMilliseconds()); } //alert('oldDate:' + tmpDate.toString() + ' & newDate:' + new_date.toString()); return new_date; } I also created a version of Now() for this to easily create dates w/o having to set a variable first. Very simple, but here it is: function Now():Date{ var today_date:Date = new Date(); return today_date; } --- In [email protected], "gevgelija50" <[EMAIL PROTECTED]> wrote: > > .NET has a nice set of date functions that will allow you to add or > subtract days from a selected date. > > For Example: > > my date is 12/31/2004 > myDate.AddDays(1) would set the myDate equal to 01/01/2005 > > From reading the documentation, I don't see such capabilities in the > Flex Date class. Is there any such functionality WITHOUT re-inventing > the wheel and writing your own function from scratch? > > Thanks, > Alex Yahoo! Groups Links Yahoo! Groups Links Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

