dbTalk Databases Forums  

Round off date function (FM 7.0v3)

comp.databases.filemaker comp.databases.filemaker


Discuss Round off date function (FM 7.0v3) in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
leon.obers@iae.nl
 
Posts: n/a

Default Round off date function (FM 7.0v3) - 09-18-2005 , 07:10 PM






Hello,

Want to get a proper "age" of persons in years.
One field (date mode) do contain the birth date of a person.
The "age" field is a calculation of "CurrentDate" minus the birth date.

Year ( Get ( CurrentDate ) - Birthdate )

If the birthday date is just in front of the current date but still in
this year (e.g. birthdays in october, november, december), the
calcualtion is made already if the person has already his birtday, so a
false "round off" upwards.

Is there a way to combine other functions that the age is given in a
proper year till the birtday date is reached?

I tried by functions like "Floor" but without result.

Thanks in advise, Leon Obers


Reply With Quote
  #2  
Old   
FP
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-18-2005 , 08:33 PM






Not the prettiest but will work

Int(
(Year(Get(CurrentDate )) +
Month(Get(CurrentDate )) / 100 +
Day(Get(CurrentDate )) / 10000)
-
(Year(BirthDate) +
Month(BirthDate) / 100 +
Day(BirthDate) / 10000))


Reply With Quote
  #3  
Old   
42
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-18-2005 , 08:45 PM



In article <1127093588.561753.231980 (AT) g47g2000cwa (DOT) googlegroups.com>,
a (AT) pottnerconsulting (DOT) ca says...
Quote:
Not the prettiest but will work

Int(
(Year(Get(CurrentDate )) +
Month(Get(CurrentDate )) / 100 +
Day(Get(CurrentDate )) / 10000)
-
(Year(BirthDate) +
Month(BirthDate) / 100 +
Day(BirthDate) / 10000))


Or more simply:

(year(currentdate)-year(birthdate)) -
if(date(month(birthdate), day(birthdate), year(currentdate)
<currentdate,1,0)


Do the calculation, as you did, and then test for the condition that
'this years' birthday hasn't happened yet, and subtract 1 if that's the
case.


Reply With Quote
  #4  
Old   
FP
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-18-2005 , 10:01 PM



Quote:
Or more simply:

(year(currentdate)-year(birthdate)) -
if(date(month(birthdate), day(birthdate), year(currentdate)
<currentdate,1,0)


Do the calculation, as you did, and then test for the condition that
'this years' birthday hasn't happened yet, and subtract 1 if that's the
case.

Your right, this is much easier.
I think you meant to have a greater than sign instead of a less than so
that is would look like:

(year(currentdate)-year(birthdate)) -
if(date(month(birthdate), day(birthdate), year(currentdate) >
currentdate,1,0)



Reply With Quote
  #5  
Old   
leon.obers@iae.nl
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-18-2005 , 10:23 PM




42 schreef:

Quote:
Do the calculation, as you did, and then test for the condition that
'this years' birthday hasn't happened yet, and subtract 1 if that's the
case.
Thanks for the quick input.
I found out that the base calculation as I wrote it down was off by 1
year to each result (one figure to high). Also to "older" birthday
dates.
So for all calculations I had to subtract the result by one.
(Year ( Get ( CurrentDate ) - Birthdate ) - 1)

In that case the calculation is done in a proper way, till just by one
day off of the birthday. Setting the computers date to a birtday. The
calculation is not updated, but only one day afterwards. (See also my
remark a few lines down).
I shall look to your formulars how I can put one day extra so the
update is done to the birthday itself (at the same date).

Another anoying thing is that once my calculation is done (by a
caculation rule within the fields properties itself). The calculation
is not updated anymore till the record itself is edited. It seems the
date has to be "refreshed". Clicking the cursor on and off within the
window doesn't help.

So switching the computers date to another value, and e.g. reloading
the Filemaker file doesn't update the calculation to another year date.
I have to edit the field of the the birtday date (using the same date),
and only after that the year age in the other field is updated again.

Is there another way to refresh the calculations automatically e.g. by
loading the file or just by a refreshing function once every 10 minutes
or so? (There is a possibility the file is used in a server version,
so files are loaded only once I guess).

Thanks, Leon Obers.



Reply With Quote
  #6  
Old   
Michael Myett
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-18-2005 , 10:37 PM



FP wrote:
Quote:
Or more simply:

(year(currentdate)-year(birthdate)) -
if(date(month(birthdate), day(birthdate), year(currentdate)
<currentdate,1,0)


Do the calculation, as you did, and then test for the condition that
'this years' birthday hasn't happened yet, and subtract 1 if that's the
case.



Your right, this is much easier.
I think you meant to have a greater than sign instead of a less than so
that is would look like:

(year(currentdate)-year(birthdate)) -
if(date(month(birthdate), day(birthdate), year(currentdate)
currentdate,1,0)

This can be simplified to

Year(curDate)-Year(birthDate) - (DayofYear(curDate) < DayofYear(birthDate))



Reply With Quote
  #7  
Old   
leon.obers@iae.nl
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-18-2005 , 11:19 PM




42 schreef:

Quote:
In article a (AT) pottnerconsulting (DOT) ca says...

Or more simply:

(year(currentdate)-year(birthdate)) -
if(date(month(birthdate), day(birthdate), year(currentdate)
<currentdate,1,0)
The following line did the trick as far as for the proper day when
switching to birtday date itself and year difference in general.

Year((Get(CurrentDate) + Day(1)) - Birthdate) - 1

(Where Birthdate is the name of a field)

Still the refreshing issue as written within the other message has to
be solved.

Leon Obers



Reply With Quote
  #8  
Old   
leon.obers@iae.nl
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-18-2005 , 11:50 PM




leon.obers (AT) iae (DOT) nl schreef:

Quote:
Still the refreshing issue as written within the other message has to
be solved.

Solved.
Okay not a very nice option but it works already within another option
I do use. Files are updated when they are exported and imported again.
(Within a script, I make use of that possibility to sort new records in
a way self relationships are seen in a special sort order).

Leon Obers



Reply With Quote
  #9  
Old   
Helpful Harry
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-19-2005 , 01:20 AM



In article <1127103578.997866.160440 (AT) g43g2000cwa (DOT) googlegroups.com>,
leon.obers (AT) iae (DOT) nl wrote:

Quote:
42 schreef:

In article a (AT) pottnerconsulting (DOT) ca says...

Or more simply:

(year(currentdate)-year(birthdate)) -
if(date(month(birthdate), day(birthdate), year(currentdate)
currentdate,1,0)

The following line did the trick as far as for the proper day when
switching to birtday date itself and year difference in general.

Year((Get(CurrentDate) + Day(1)) - Birthdate) - 1

snip

Since the original question has been answered, I only have one quick
note. When adding days to a date you don't need the Day function.
FileMaker's dates work in days, so you simply add (or subtract) the
number of days.
eg.
Get(CurrentDate) + 1 adds one day

MyDateField - 3 subtracts three days

TextToDate("18/5/2004") + 7 adds seven days (ie. 1 week)

The same is true for times in FileMaker - they work in minutes, so you
can simply add (or subtract) minutes by adding just the number and
FileMaker will calculate the result properly.
eg.
Get(CurrentTime) - 15 subtracts 15 minutes

MyTimeField + 125 adds 125 minutes
(ie. 2 hours and 5 minutes)



Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #10  
Old   
Remi-Noel Menegaux
 
Posts: n/a

Default Re: Round off date function (FM 7.0v3) - 09-19-2005 , 01:27 PM



Quote:
When adding days to a date you don't need the Day function.
FileMaker's dates work in days, so you simply add (or subtract) the
number of days.
eg.
Get(CurrentDate) + 1 adds one day
MyDateField - 3 subtracts three days
TextToDate("18/5/2004") + 7 adds seven days (ie. 1 week)
This is right.

Quote:
The same is true for times in FileMaker - they work in minutes, so you
can simply add (or subtract) minutes by adding just the number and
FileMaker will calculate the result properly.
eg.
Get(CurrentTime) - 15 subtracts 15 minutes
MyTimeField + 125 adds 125 minutes
(ie. 2 hours and 5 minutes)

This is wrong (at least for FMP6). FileMaker count the times in seconds
and not in minutes.

Remi-Noel




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.