Gossamer Forum
Home : Products : DBMan : Customization :

Date plus number of days

Quote Reply
Date plus number of days
I have a field 'Date' in unix format (dd-mmm-yyyy)

I want to do a range search on this field for:
Lower range: Date equals the date entered by viewer
Upper range: + number of days as entered by viewer

This is to allow viewers to search for events between the 'start date' and the 'start date + the number of days'.

Is this possible?

I've tried the -gt -lt searches on the Date field with the lower range being one day earlier than the Date entered using the mods discussed on the forum but got a misconfiguration error.

Thanks
Alba
Quote Reply
Re: [Alba] Date plus number of days In reply to
Check out the tread with the following title by search in the forum here, or checking out the FAQ noted below under the section "Dates".

search against DateAdded field

User: long327
Posted: 26-Jul-00

There are also other related thread in the FAQ noted below.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Date plus number of days In reply to
Thanks for your reply.

The date entry is a text box (there are 365 dates to choose from). I tried modifying the codes in the messages you suggested but just got a configuration error.

I tried using the mod where the date is shifted to the day before.

The other option is having a -gt or eq Date search but I couldn't get these to work either.

I updated the sub get_date so that is not the problem.

Have you any other ideas?

Thanks again
Alba
Quote Reply
Re: [Alba] Date plus number of days In reply to
If you would post a text copy of your html.pl file and provide the url to where it can be viewed. Plus show us your

sub get_date
and
sub date_to_unix

from your db.cgi file into your post we can try and help you to get it working.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Date plus number of days In reply to
Thanks for your help,

I tried a mod where the Date-gt is automatically changed to the previous day for the purposes of the search
ie: Date entered as 01-May-2004 does a search on Date-gt than 31-Apr-2004.

Either this mod or a Date => would be really useful. I want the viewers to enter the date as dd-mmm-yyyy.

Test website: www.lochaber-property.co.uk/cgi-bin/dbman/db.cgi?db=avail

requested subs as below:
=======================================
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 ($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";
}

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 (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($day, $mon, $year) = split(/-/, $_[0]);
unless ($day and $mon and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
Quote Reply
Re: [Alba] Date plus number of days In reply to
In your sub html_view_search

You have which will cause you problems:

<form action="$db_script_url?sb=2&so=ascend&mh=40" method="GET">

If you want to include options for sorting you would use something like this for example:

<FORM ACTION="$db_script_url" METHOD="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="sb" value="2">
<input type=hidden name="so" value="ascend">

maximum hits would be defined within your .cfg file.

Also you have the codes for the search within your html_record_form. You should setup a separate search form to perform the search.

Here's some instructions from the FAQ:

"greater than" and "less than" search on one date field

You can perform a "greater than" and "less than" search on one date field within DBMan.

Assuming your field name which holds the date is called "Date," add the following fields to your
search form:

code:

Dates after: <input type="text" name="Date-gt">
Dates before: <input type="text" name="Date-lt">

(You would probably want to make a search form that is separate from your add/modify form.)
Then, you would just enter the dates in the fields and it would do the search.

You can also find examples of creating a custom search form in the FAQ noted below under the section "Searching". Using that date format you might also want to check out the date translator mod as it may be needed to use this kind of date format for the type of searching you want to do. Try it without and if you have problems then check that sub for instructions on how it is used.

Have you searched through the FAQ under dates for examples of setting up range searches?

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Date plus number of days In reply to
Thank you for your help. I've now got the test database running properly.

Alba