Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Countdown using years, months, days in the calculated answer

Status
Not open for further replies.

MorganNews

Technical User
Feb 7, 2004
1
0
0
CA
I've spent fruitless hours on this one.

The problem: I want to produce a calculated text statement that says a specific date of an event that I enter is, only for example, 5 years, 4 months and 21 days from another specific future date.

The details: The specific future date, the end of the countdown, is Feb 12, 2010, and the entry date is some random date closer to now than that. Let's say the entry date is Feb 11, 2004. I want Filemaker to calculate the years, months and days between the two.

If I subtract using the date function to get the answer in years, for instance, I get 6, which is correct. However, if the entry date is Feb 13, 2004, I also get 6 years, which is (for my purposes) incorrect, because the correct answer is that Feb 13, 2004 is 5 years, 11 months and (don't forget the leap year)16 days from Feb 12, 2010.

I have tried innumerable but unsuccessful variations on the theme of:
(Date(2,12,2010)-Date(Day(Entry Date),Month(Entry Date),Year(Entry Date) as well as variations of, say: month(Date(2,12,2010)-month(Entry Date).

But usually, the years, months or days are wrong for my purposes. Sometimes they are correct for dates on one side of the anniversarys of the countdown date, but not on the other. In the example above, the calculation for the years is correct only up to Feb 12 of any given year, and then it's wrong. Sometimes I get minus numbers for, say, the days or the months, which would also be incorrect. So, I'm also having problems getting the correct answer for months and days from the 2010 date that's correct in all instances.

The question: How do I get the answer that's correct for what I'm trying to achieve?
 
MorganNews,

Get DayDiff first.
DayDiff = date(DDB, MMB, 2004) - date(DDA, MMA, SpecYear)
where SpecYear = case(MMB > MMA, 2004, 2003)
Next MonthDiff = case(MMB > MMA, MMB-MMA, MMB + 12 - MMA)
Finally, YearDiff = case(MMB > MMA, YearB - YearA, YearB - YearA + 1)

I have dodged providing for the = cases. I'm sure you casn work them out. Also, you need to combine the above lot into one calculation; I left it in bits for clarity(?)



Cheers,
Paul J.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top