Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Compare Add_Date with actual server-date?

Quote Reply
Compare Add_Date with actual server-date?
Hi folks,

i want to offer this search:

Give me all Links, where between "Add_Date" and the "actual Server Date" are X Days!

e.g. show me all links, which are exactly 3 days old!

Is that possible?

Thanks in advanced!

Coyu
Quote Reply
Re: [Coyu] Compare Add_Date with actual server-date? In reply to
I don't think its possible without a Plugin.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Compare Add_Date with actual server-date? In reply to
Hmmm...

OK!

You can extract the server-date and you have the Add_Date in the db.

Perhaps javascript? Any ideas?

Coyu
Quote Reply
Re: [Coyu] Compare Add_Date with actual server-date? In reply to
I think you can use a global. You may need to add use GT::Date;

sub {
my ($output,$sth,$link);
my $date = GT::Date::get_date();

my $newdate = date_sub($date, 7); #This is for links added 7 days before now.
my $search_db = $DB->table('Links');
$sth = $search_db->select ( {isValidated => 'Yes', Add_Date => $newdate });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}
Quote Reply
Re: [afinlr] Compare Add_Date with actual server-date? In reply to
Hi,

what do you mean?
Should i generate a new global? Can i save this in "globals"?
And how can i use a specific Query?

Thanks afinir!
Quote Reply
Re: [Coyu] Compare Add_Date with actual server-date? In reply to
Hi, Yes you'll need to save it in your globals list. If you call it something like days_old then you would use the tag <%days_old('7')%> if you want to show all the links which are 7 days old.

sub {
my ($output,$sth,$link);

my $daysold=shift || 1;
my $date = GT::Date::get_date();

my $newdate = date_sub($date, $daysold);
my $search_db = $DB->table('Links');
$sth = $search_db->select ( {isValidated => 'Yes', Add_Date => $newdate });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}

Last edited by:

afinlr: Jul 31, 2003, 5:01 PM
Quote Reply
Re: [afinlr] Compare Add_Date with actual server-date? In reply to
A fatal error has occured:
GT::Date (7619, GT::AutoLoader): Unknown method 'get_date' called at (eval 21) line 5.


Please enable debugging in setup for more details.



But i have another Problem: I have in the table "Links" a column named "Expire_Date" in date-form!

So i want to use something like:
- This Link will expire in X days!
And in the search:
- Show me all links, which expire in 2, 3, 4, 10 days, etc.


I think u have only to compare the actual date and the Expire_Date. Thats it!
Because all Expired_Links will be automatically deleted from the database, there cannot be a negative number!


e.g. 2003-08-05 (Expire) - 2003-08-01 (today) = 4 (days between)

Is that possible?

Thanks in advance!
Quote Reply
Re: [Coyu] Compare Add_Date with actual server-date? In reply to
Oops - it is date_get rather than get_date. Sorry.

If you want to do, 'show me all the links that expire in 2 days', you could use page.cgi

/cgi-bin/page.cgi?p=template&days=2

where template.html is the name of the template you are using.

In the template use the global <%daystogo%>

sub {
my ($output,$sth,$link);
my $tags=shift;
my $daystogo=$tags->{days};
my $date = GT::Date::date_get();

my $newdate = date_add($date, $daystogo);
my $search_db = $DB->table('Links');
$sth = $search_db->select ( {isValidated => 'Yes', Expire_Date => $newdate });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}

To show the number of days to go in the link template, I think you can use a tag instead of a global. You might want to set the variable $today in a global though.

This Link will expire in <%set today=GT::Date::date_get%><%GT::Date::date_diff($Expire_Date,$today)%> days!

Last edited by:

afinlr: Jul 31, 2003, 5:35 PM
Quote Reply
Re: [afinlr] Compare Add_Date with actual server-date? In reply to
Hi afinir!

1. Days Old
It doesnt works! :-(
I am using your global:


sub {
my ($output,$sth,$link);

my $daysold=shift || 1;
my $date = GT::Date::date_get();

my $newdate = date_sub($date, $daysold);
my $search_db = $DB->table('Links');
$sth = $search_db->select ( {isValidated => 'Yes', Add_Date => $newdate });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}


2. Days to Expire Tag
Your tag works! :-) Thanks a lot!!!

3. Search for Expire-Tag (with your global)
I dont know, what you mean? I need in my search form only a possibility to search like:
"days_to_expire = 3" or
"days_to_expire >= 3" or
"days_to_expire < 6"...

I do not understand your proceeding, but i do it :-)
I use your global <%daystogo%> in the new page "_test" ive created. But there is an error when i call it. Look yourself: http://www.freewinner.de/cgi-bin/gs/page.cgi?p=_test&d=1
What i do wrong?

Thanks in advance
Coyu
Quote Reply
Re: [Coyu] Compare Add_Date with actual server-date? In reply to
Sorry - its always a mistake replying to posts at 1.30am!

Right, I've just tested this on my site so hopefully it should work. You need to call this with <%daysold('7')%> to show all links which are seven days old.

sub {
Links::init_date();

my ($output,$sth,$link);
my $daysold=shift;
unless ($daysold =~ /^\d+$/){$daysold=1;}
my $date = GT::Date::date_get();
my $newdate = GT::Date::date_sub($date, $daysold);
my $search_db = $DB->table('Links');
$sth = $search_db->select ( {isValidated => 'Yes', Add_Date => $newdate });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}

I didn't realise you wanted to use the expire within the search form. I *think* you can do this more simply than using the global. If you use a select dropdown, for each option you could have something like this

(you will need this tag somewhere near the top of your page unless you are using a global to define today <%set today=GT::Date::date_get%>)

<select name=name="Expire_Date-lt"> (this is for Expire_Date less than or equal to - change it to "Expire_Date" for exact values)

<option value="<%GT::Date::date_add($today,'1')%>">1 day

<option value="<%GT::Date::date_add($today,'2')%>">2 days

I haven't tested this so I'm not sure whether this less than query works with dates but I assume it does.
Quote Reply
Re: [afinlr] Compare Add_Date with actual server-date? In reply to
Hi afinir!

It Works! :-) Thanks!

What should i do, when i want to show all the links, that exired in one week (7 days)?

So, when today is 2003-08-05, i want all links, that expires from today until 2003-08-12

Is that possible?

Thanks in advance!

Coyu

In Reply To:
I didn't realise you wanted to use the expire within the search form. I *think* you can do this more simply than using the global. If you use a select dropdown, for each option you could have something like this

(you will need this tag somewhere near the top of your page unless you are using a global to define today <%set today=GT::Date::date_get%>)

<select name=name="Expire_Date-lt"> (this is for Expire_Date less than or equal to - change it to "Expire_Date" for exact values)

<option value="<%GT::Date::date_add($today,'1')%>">1 day

<option value="<%GT::Date::date_add($today,'2')%>">2 days

I haven't tested this so I'm not sure whether this less than query works with dates but I assume it does.
Quote Reply
Re: [Coyu] Compare Add_Date with actual server-date? In reply to
Hi,

That's what the Expire_Date-lt should do. The -lt on the end should choose records where the date is less than (or equal to I think) the date that you feed in. As I said, I'm not sure whether this does work with dates.
Quote Reply
Re: [afinlr] Compare Add_Date with actual server-date? In reply to
Thanks afinlr for the following code, but I can't seem to get it to work properly on 3.1.0 installation:


This Link will expire in <%set today=GT::Date::date_get%><%GT::Date::date_diff($Expire_Date,$today)%> days!

I changed
$Expiry_Date To $ExpiryDate



This Link will expire in <%set today=GT::Date::date_get%><%GT::Date::date_diff($ExpiryDate,$today)%> days!
Quote Reply
Re: [rascal] Compare Add_Date with actual server-date? In reply to
What is shown when you use this? What is shown for <%ExpiryDate%> and <%today%>?
Quote Reply
Re: [afinlr] Compare Add_Date with actual server-date? In reply to
Hi afinlr,

using: <%set today=GT::Date::date_get%> <%today%> = 2006-06-23

<%ExpiryDate%> = 1181447692
Quote Reply
Re: [rascal] Compare Add_Date with actual server-date? In reply to
ExpiryDate needs to be in a date format to use this (I think Expire_Date above was a custom field).
I think you might be able to do this:

This Link will expire in <%set today=GT::Date::date_get%><%set expire=GT::Date::date_get($ExpiryDate,'%yyyy%-%mm%-%dd%')%><%GT::Date::date_diff($expire,$today)%> days!
Quote Reply
Re: [afinlr] Compare Add_Date with actual server-date? In reply to
Thanks for helping with this, I tryed the last code and got this:

This Link will expire in -38478 days!
Quote Reply
Re: [rascal] Compare Add_Date with actual server-date? In reply to
Just tested it on my site and it works perfectly - for sites which have an expiry date. Those that aren't paid listings give a big negative number - but not the same one you have. Does the link you are looking at definitely have an expiry date? What is the value for <%expire%>?
Quote Reply
Re: [afinlr] Compare Add_Date with actual server-date? In reply to
Oh Boy, your right I was looking at a link that never expires.

Thank You, it works!!!!!!