Hi Matt,

If what you're looking for is a way to subtract two dates, then it's your
lucky day...
I just wrote an Age Counter component that displays how long it's been since
a specific date (years, months, hours, minutes, and seconds). It's for a
client who wants to show how long his pediatric center has been running (a
very long time...): http://www.belilovskypediatrics.com/en/about.htm


Anyway, you don't need the whole class, just the relevant function which is:

 function getAge (year:Number, month:Number, day:Number):Date {
                //Founded day or birthday
                var founded:Date = new Date (year, month, day);
                //Today
                var today:Date = new Date ();
                //Time difference in milliseconds
                var mil:Number = today.getTime () - founded.getTime ();
                //The age, in a date format
                var age:Date = new Date ();
                //Set the age (in relateion to 1970)
                age.setTime (mil);
                //Adjust the year
                age.setYear (age.getYear () - 70);
                return age;
}

The function returns a Date format, from which you can easily extrapolate
everything you need -

var age:Date = AgeCounter.getAge (1970, 6, 12); //That's my birthday, send
me a card ;)

Note: The month is 0 based, so don't send me that card in June, but in July
;)
The day is 1 based, so my birthday is indeed on the 12th

And get the various age differences between dates like this: age.getYear(),
age.getMonth(), age.getDate(), age.getHour(), age.getSecond()

If you need exact hours, just add them to the method. See docs for creating
a Date object.

Anyone - let me know if you want the AgeCounter component itself, I'll post
it on the blog.

Cheers,
Karina






  

> -----Original Message-----
> From: matt ganz [mailto:[EMAIL PROTECTED] 
> Sent: 27 April 2006 18:18
> To: Flashcoders mailing list
> Subject: [Flashcoders] calculating dates based on a starting date.
> 
> hi. 
> 
> i'm building a scheduler app for people who need infusions 
> over a 1 year period.  a user selects the following info to begin:
> 
> 1. a starting date for first infusion - day, month, and year 
> 2. number of infusions - 1-4 3. frequency of infusions - 
> every 1, 2, 3, or 4 weeks.
> 
> i have to come up with a schedule of infusion dates over the 
> next 13 months. 
> 
> the breakdown of infusion frequency goes like this:
> 
> CASE 1: user selects infusions per 1 week period.
> a. 1 infusion every week -> increment every 7 days b. 2 
> infusions "" -> increment every 4 days c. 3 infusions "" -> 
> increment every 2 days d. 4 infusions "" -> alert ("max 3 
> infusions/week" );
> 
> CASE 2: user selects infusions per 2 week period.
> a. 1 infusion every 2 weeks -> increment every 14 days b. 2 
> infusions "" -> increment every 7 days c. 3 infusions "" -> 
> increment every 4 days d. 4 infusions "" -> increment every 4 days
>  
> CASE 3: user selects infusions per 3 week period.
> a. 1 infusion every 3 weeks -> increment every 21 days b. 2 
> infusions "" -> increment every 10 days c. 3 infusions "" -> 
> increment every 7 days d. 4 infusions "" -> increment every 5 days
> 
> CASE 4: user selects infusions per 4 week period.
> a. 1 infusion every 4 weeks -> increment every 28 days b. 2 
> infusions "" -> increment every 14 days c. 3 infusions "" -> 
> increment every 9 days d. 4 infusions "" -> increment every 7 days
> 
> the way i figured to do it would be to capture the starting 
> day and month and then calculate ( based on number of 
> infusions and frequency ) every other day and month over a 13 
> month period. i'd throw all of these values into an 
> 'infusionDates' array and then i can loop over them and 
> change the properties of the DateChooser that i need. 
> 
> i just need help figuring out how to populate the 
> infusionDates array. can anyone help me get started, please? 
> 
> thanks for any tips. -- matt. 
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training 
> http://www.figleaf.com http://training.figleaf.com
> 
> 

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to