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

Birthday Global (0000-00-00)

Quote Reply
Birthday Global (0000-00-00)
Input Field: 1983-11-04

How can I make this to read: Nov. 04 1983 ? Is there a global for that?
Quote Reply
Re: [mrcry11] Birthday Global (0000-00-00) In reply to
Hi,

You don't need a global. Try this tag

<%GT::Date::date_transform($variable,'%yyyy%-%mm%-%dd%',%mmm%. %dd% %yyyy%')%>

you'll need to replace variable with the name of your variable but make sure you keep the $.

You can find a lot more information about date formats in your admin directory at

http://yoursite.com/...;topic=/GT/Date.html

Laura.
The UK High Street
Quote Reply
Re: [afinlr] Birthday Global (0000-00-00) In reply to
Thanks for your reply..

Another question:

Today date - Birthday date = Age?

Output: I'm 18 yrs old? Can you do this?
Quote Reply
Re: [mrcry11] Birthday Global (0000-00-00) In reply to
You can do:

<%GT::Date::date_diff($day1, $day2)%>

and it will return the number of days difference between the two days. You could take that and divide it by 365 to get the age. Should work. =)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Birthday Global (0000-00-00) In reply to
In Reply To:
You can do:

<%GT::Date::date_diff($day1, $day2)%>

and it will return the number of days difference between the two days. You could take that and divide it by 365 to get the age. Should work. =)

Cheers,

Alex
How can I make one date "today's day" - $day1?
Quote Reply
Re: [mrcry11] Birthday Global (0000-00-00) In reply to
I got this to work but I want to double check with the experts of GT. Possible tweaks?

sub {
Links::init_date();
my $year = $_[0]->{dobyear};
my $month = $_[0]->{dobmonth};
my $day = $_[0]->{dobday};

my $date = GT::Date::date_get();
my $datey = GT::Date::date_transform($date,'%yyyy%-%mm%-%dd%','%yyyy%');
my $datem = GT::Date::date_transform($date,'%yyyy%-%mm%-%dd%','%mm%');
my $dated = GT::Date::date_transform($date,'%yyyy%-%mm%-%dd%','%dd%');

if ($month < $datem) {
return sprintf("%.0f", ($datey - $year));
}

if ($month > $datem) {
return sprintf("%.0f", (($datey - $year)-1));
}

if ($month = $datem) {
if ($day <= $dated) {
return sprintf("%.0f", ($datey - $year));
}

if ($day > $dated) {
return sprintf("%.0f", (($datey - $year)-1));
}
}
}
Quote Reply
Re: [mrcry11] Birthday Global (0000-00-00) In reply to
Well, I'm not expert of GT, but my input may also helps you a bit. Wink

If I'm correct, you want 3 input values from template tags (dobyear, dobmonth, dobday), and you want as output how old is the user in years. Right?
If yes, then try out the first, and if it works, then the second optimized version.

The longer (not optimized) version of the years_old global may look like:
Code:
sub {
Links::init_date(); # not sure if we really need this, as it was already initialized at cgi start
my $birthdate = shift; # we input a %yyyy%-%mm%-%dd% style date, so I don't set the date format
my $date = GT::Date::date_get();

my $days_difference = GT::Date::date_diff($date, $birthdate);
my $years_difference = INT($days_difference / 365);

return $years_difference;
}

A shorter optimized version of the years_old global may look like:
Code:
sub {
Links::init_date(); # still not sure if we really need this, as it was already initialized at cgi start
return INT(GT::Date::date_diff(GT::Date::date_get(), shift) / 365);
}

You should call it with:
Code:
<%years_old($dobyear, $dobmonth, $dobday)%>

I had no time to try it out, but I think the logic is good.
If it doesn't work, I will help you out tomorrow, with another corrected global.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Mar 19, 2003, 7:23 PM
Quote Reply
Re: [webmaster33] Birthday Global (0000-00-00) In reply to
Your "optimized" version has syntax problems. INT() is a non-existant perl function. You need to be careful with case sensitivity. INT() is different from int()
Quote Reply
Re: [Paul] Birthday Global (0000-00-00) In reply to
Uhm, sorry about the syntax problem. I had no time to check if it works.

So, after correcting the syntax problem Paul pointed use this:
Code:
sub {
Links::init_date(); # still not sure if we really need this, as it was already initialized at cgi start
return int(GT::Date::date_diff(GT::Date::date_get(), shift) / 365);
}

Also its still not tested code, but IMO should work.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Birthday Global (0000-00-00) In reply to
How could you make it print:

Happy Birthday (when it is that day)?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Birthday Global (0000-00-00) In reply to
Well it's a different global you need.

Here's happy_birthday global:
Code:
sub {
my $bmonth = shift;
my $bday = shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
return (($bmonth eq $mon+1) and ($bday eq $mday)) ? "Happy Birthday" : '';
}

A shorter optimized version:
Code:
sub {
my @time = localtime(time);
return ((shift eq $time[4]+1) and (shift eq $time[3])) ? "Happy Birthday" : '';
}

Use like this in templates:
Code:
<%happy_birthday($dobmonth, $dobday)%>

It was just a quick coding, and I did not try out. So it's not guaranteed it's bug free.
Also I supposed the input values were validated on the user registration form already, so I don't check if there is a valid value or not.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Birthday Global (0000-00-00) In reply to
Hi,

Thanks - both versions worked :-)

Klaus

http://www.ameinfo.com
Quote Reply
Re: [webmaster33] Birthday Global (0000-00-00) In reply to
Hi,

Is it possible to do this at the query level? this solution requires before hand knowledge of both variables. For a very large database where you want to scan the stored Birthdate and compare vs today's date you'll have to full scan the table.

Can we just query the date field in the DB asking only for month and day assuming that the stored value in the DB is in the format YYYY-MM-DD?
Quote Reply
Re: [jaltuve] Birthday Global (0000-00-00) In reply to
Quote:
Can we just query the date field in the DB asking only for month and day assuming that the stored value in the DB is in the format YYYY-MM-DD?
I believe you can simply query from the database those clients which has a birthday.
When looking for birthdays on 25 of August, you just need to use the LIKE '%-08-25'.
It's not a detailed query example, but this is base of it.

I hope this is what you asked. If not, let me know how you meant.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Birthday Global (0000-00-00) In reply to
In Reply To:
Quote:
birthdays on 25 of August

Now that is an excellent choice of birthdays..
Quote Reply
Re: [jaltuve] Birthday Global (0000-00-00) In reply to
Alternatively, you can use mysql date functions within a condition - here are some examples:

GT::SQL::Condition->new( 'YEAR(Date)', '=', $year, 'MONTH(Date)', '=', $month, 'DAYOFMONTH(Date)', '=', $day);