Gossamer Forum
Home : Products : DBMan : Customization :

Number of days a record has been in the database

Quote Reply
Number of days a record has been in the database
Okay, on to my next problem. Wink

I'd like to create a field in which is shown how many days a record has been in the database. Has this been done before, and is it possible at all?

Think this is gonna be a hard one.

Thijs
Quote Reply
Re: Number of days a record has been in the database In reply to
Actually, quite simple and no new field required... assuming you have a field called Date which is the date the record was added, the following should work...
Code:
$sec_since = time() - &date_to_unix($rec{'Date'});
$days_since = int($sec_since / 86400);
print qq|This record has been in the DB for $days_since days...|;
I've split it up into two steps to show what is going on... you could consolidate the $days_since calculation to one line, but I leave that exercise up to you. Wink

------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)

Quote Reply
Re: Number of days a record has been in the database In reply to
Hi I want to have a field that shows the number of days a record has been in the database..i tried adding the code provided, but it doesn't work. Where am I suppose to put the code???

Reena
Quote Reply
Re: Number of days a record has been in the database In reply to
You would add the codes to:

sub html_record_long or html_record_long
after:
my (%rec) = @_;

$sec_since = time() - &date_to_unix($rec{'Date'});
$days_since = int($sec_since / 86400);

And then at the bottom of the record or where you want to display the number of days you would add:

print qq|This record has been in the DB for $days_since days...|;

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Number of days a record has been in the database In reply to
Hi I tried using the code supplied, but i keep getting the same number for all of the records --> 11174...whats going on?

Reena
Quote Reply
Re: Number of days a record has been in the database In reply to
one more thing..is there anyway to only calculate the # of days open if my Case Status (select box) is Open. So only calculate the days open...once the Case Status is changed to close then stop doing the calculations, but i still want # of days open to show on the record

Reena