Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

date to age help (tag or global?)

Quote Reply
date to age help (tag or global?)
I want to calculate a person's age from their date of birth.

Their date of birth is in the field prof_birthday within GT community and I can call it into my LSQL templates.

<%Plugins::Auth_Community::get_profile($LinkOwner)%>
<%prof_birthday%>


I can also get the current date into the templates but when I attempt to calculate the difference, I only get the year of birth.

I want to find the number of days difference between the current date and date of birth, then divide by 365 to get the age. (it's for children so I'm not too bothered about leap years).

Can anybody help me with either:
  • the correct way to calculate the age within the template.
  • a global to calculate the above.

I know there are discussions within the forum along similar lines and I've also looked in the help files but I cannot work out how to do this.

Thanks for your help.
Quote Reply
Re: [Alba] date to age help (tag or global?) In reply to
Hi,

You could try;

<%global_name($prof_birthday)%>

Code:
sub { return GT::Date::date_diff($_[0],GT::Date::date_get()) / 365; }

... which would give approximatly the number of years between the current date, and their birthday.

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] date to age help (tag or global?) In reply to
Hi Andy

That works, thanks. To get a positive; I reversed it to read
return GT::Date::date_diff(GT::Date::date_get(),$_[0]) / 365;}

It is giving several decimal places; is there a way of limiting it to the whole number?

Thanks.

Last edited by:

Alba: Apr 4, 2005, 11:50 AM
Quote Reply
Re: [Alba] date to age help (tag or global?) In reply to
Quote:
return GT::Date::date_diff(GT::Date::date_get(),$_[0]) / 365;}


To

Quote:

return GT::Date::date_diff(GT::Date::date_get(),$_[0]) div 365;}


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] date to age help (tag or global?) In reply to
Thanks,

return GT::Date::date_diff(GT::Date::date_get(),$_[0]) div 365;}

Unfortunately this code gives me a syntax error.

Something strange is also happening, when I first tried the original code it gave me a correct age; now it is giving age - 10 years. I can only assume something has happened to the date on the server.
Quote Reply
Re: [Alba] date to age help (tag or global?) In reply to
sub { return int( GT::Date::date_diff($_[0],GT::Date::date_get()) / 365) ; }

give that a try



PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] date to age help (tag or global?) In reply to
Thanks, that works and I reversed it to give me a positive number.

sub {
return int( GT::Date::date_diff(GT::Date::date_get(),$_[0]) / 365) ;
}