Gossamer Forum
Home : Products : DBMan : Installation :

automatic input of future date

Quote Reply
automatic input of future date
Is there some way I can create a date field that will automatically show a date a week from the present present date.

Thanks
Stan
Quote Reply
Re: automatic input of future date In reply to
Do you want the "week later" date entered when the record is added?

If so, I would copy the get_date subroutine and put it in another subroutine -- call it get_date7. It would be like:

Code:
sub get_date7 {
$time = time() + 604800; # 604800 = 7 days times 86400 seconds per day
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$months[$mon]-$year";
}

Put the above subroutine somewhere in db.cgi. (It can go anywhere, really, as long as it's not in the middle of another subroutine.)

Then, in the .cfg file, in the field definition where you want this to go, put

&get_date7

for the default value.


------------------
JPD

All my advice is offered on the basis of kindness-ware. If I've helped you to solve a problem, go out of your way to be kind to someone today.

Quote Reply
Re: automatic input of future date In reply to
Even better, replace get_date with:

Code:
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.
#
my $time = shift | | time();
my ($day, $mon, $year) = (localtime($time))[3,4,5];
my @months = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}

Then you can call &get_date() to get the current date, &get_date(time + 604800) to get 7 days from now, &get_date (time + 86400) to get tommorrow, etc.

Note: UBB replaces double pipe with pipe space pipe, be sure to switch it back!

Cheers,

Alex

[This message has been edited by Alex (edited March 03, 1999).]
Quote Reply
Re: automatic input of future date In reply to
Alex,

Can you use "&get_date(time + 86400)" in the .cfg file for a default value? I wasn't sure you could, which is why I went by my circuitous route. If you can, that's great!


------------------
JPD

All my advice is offered on the basis of kindness-ware. If I've helped you to solve a problem, go out of your way to be kind to someone today.