Gossamer Forum
Home : Products : DBMan : Customization :

Birthdate match to server date

Quote Reply
Birthdate match to server date
I have forced user to add the three fields, date,month,year.
#changed to JPDeni date http://webmagic.hypermart.net/dbman/calc42.txt
sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yy".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.
$time = $_[0];
($time) || ($time = time());
# be sure to remove the space between the two | characters in the line above.
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
++$mon;
($mon < 10) and ($mon = "0$mon");
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$mon-$year";
}
#changed to JPDeni date http://webmagic.hypermart.net/dbman/calc42.txt
#due to want to count age of user
sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = $_[0];
my ($time);
my ($day, $mon, $year) = split(/-/, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$day = int($day); $mon = int($mon) - 1 ; $year = int($year) - 1900;
$time = timelocal(0,0,0,$day,$mon,$year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}

I want to have a page list of record that have the date and month match to server date and month.Such as if to day is 09-02-2001,the records which have date match to server date will be listed on a page.

Any comment or please help me code it if you know how to.

Regards,
Act.
I am new to cgi, Thank you for your help.
Quote Reply
Re: Birthdate match to server date In reply to
You will need to create a variable called $birthdate in the sub html_record routine:

Code:

my $birthdate = "$rec{'Day'}-$rec{'Month'}-$rec{'Year'}";


Then replace the individual date fields, with the following code:

Code:

$birthdate


Of course, the better approach would be to have ONE birthdate field called Birthdate and then use the following to add the date in the correct format:

1) Add the following codes in your html.pl file:

Code:

sub build_date_select_fields {
# --------------------------------------------------------
# Fancy Display of Fields.

my $field = $_[0];
my $compare = $_[1];
my %selector = (
'Day' => [
['1','1'],
['2','2'],
['3','3'],
['4','4'],
['5','5'],
['6','6'],
['7','7'],
['8','8'],
['9','9'],
['10','10'],
['11','11'],
['12','12'],
['13','13'],
['14','14'],
['15','15'],
['16','16'],
['17','17'],
['18','18'],
['19','19'],
['20','20'],
['21','21'],
['22','22'],
['23','23'],
['24','24'],
['25','25'],
['26','26'],
['27','27'],
['28','28'],
['29','29'],
['30','30'],
['31','31']
],
'Month' => [
['Jan','January'],
['Feb','February'],
['Mar','March'],
['Apr','April'],
['May','May'],
['Jun','June'],
['Jul','July'],
['Aug','August'],
['Sep','September'],
['Oct','October'],
['Nov','November'],
['Dec','December']
],
'Year' => [
['2000','2000'],
['2001','2001'],
['2002','2002'],
['2003','2003'],
['2004','2004'],
['2005','2005'],
['2006','2006'],
['2007','2007'],
['2008','2008'],
['2009','2009'],
['2010','2010']
],
);
$output = qq|<SELECT NAME="$field">\n|;
$i = 0;
while ( $selector{$field}[$i][0] ) {
$selector{$field}[$i][0] eq $compare ?
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]" SELECTED>$selector{$field}[$i][1]\n|) :
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]">$selector{$field}[$i][1]\n|);
$i;
}
if ($i) { $output .= "</SELECT>"; }
else { $output = "Incorrect field definition"; }
return $output;
}


2) Then you will need to add the following codes in the sub html_record_form routine:

Code:

|; print &build_date_select_fields("Day",$field{'Day'});
|; print &build_date_select_fields("Month",$field{'Month'});
|; print &build_date_select_fields("Year",$field{'Year'});


3) Then in the sub add_record routine in the db.cgi script, add the following codes:

Code:

$rec{'BirthDate'} = "$in{'Day'}-$in{'Month'}-$in{'Year'}";


Regards,

Eliot Lee
Quote Reply
Re: Birthdate match to server date In reply to
Your question was:

I want to have a page list of record that have the date and month match to server date and month. Such as if to
day is 09-02-2001,the records which have date match to server date will be listed on a page.

I think if you look at the following mod it may provide you some tips on how to display what you want.

Event Calendar - This modification allows you get a up to date list of events. Events older than today will not be shown.

http://gossamer-threads.com/...tach/616-events.html

Hope this helps


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Birthdate match to server date In reply to
Ok may be my english is messy
My question was;
I want to have a page list of record that have the date and month match to server date and month. Such as if to
day is 09-02-2001,the users' records which have Birthday (dd-mm-yyyy)match to server date (today date; dd-mm) will be listed on a page.Just want to announce to others that today we have birthday of someusers.

LoisC, the http://gossamer-threads.com/scripts/resources/Attach/616-events.html was very disorder,it should be in .txt not .html.I will try it.

Regards,
Act.
I am new to cgi, Thank you for your help.
Quote Reply
Re: Birthdate match to server date In reply to
Hi, Eliot
I not try your codeing yet but before to done with it,i wonder something;
------------------ part of your codeing------------

'Month' => [['Jan','January'],['Feb','February'],['Mar','March'],['Apr','April'],['May','May'],['Jun','June'],['Jul','July'],['Aug','August'],['Sep','September'],['Oct','October'],['Nov','November'],['Dec','December']],'Year' => [['2000','2000'],['2001','2001'],['2002','2002'],['2003','2003'],['2004','2004'],['2005','2005'],['2006','2006'],['2007','2007'],['2008','2008'],['2009','2009'],['2010','2010']

------------------end part of your codeing------------
about Month,I have change my get_date in .cgi file to JPDeni date, http://webmagic.hypermart.net/dbman/calc42.txt ,and I force user add 3 fields of dd-mm-yyyy.All three fields are digits,month is not jan,feb,...

So i wonder if your code above will work with my solution or not?Thank you

Regards,
Act.
I am new to cgi, Thank you for your help.
Quote Reply
Re: Birthdate match to server date In reply to
Yes, it will

Regards,

Eliot Lee
Quote Reply
Re: Birthdate match to server date In reply to
This is ALMOST exactly what I need for somehting I'm doing for an event calendar.

User need to be able to enter a start date and a finish date for events. I'd like to use this type of drop down box to make it easy, but I just can't get it to work.

It either gives me an "Incorrect field definition" or the page stops loading at the drop down list.

Can you giove me any pointers as to how I can adapt this to handle two dates?

Thanks a lot

Mat

Quote Reply
Re: Birthdate match to server date In reply to
Mat:

You might want to check the FAQ noted below and look under the section "Dates"

There you will find 2 threads which will be useful in creating your events calendar.

Drop down menu for Date
and
Calling entries depending on current Date

you may also need/want to install the date translator mod to be able to search between dates.

The first referenced thread is another method of using a dropdown menu with perhaps more instructions provided.

Hope this helps

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/