Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Only show if date is greater than NOW()

Quote Reply
Only show if date is greater than NOW()
Hi,

I have added a two new fields so that I can add special offers to my directory listings, which expire on a certain date. I'm using these fields, "special" (the details of the offer) and "special_end" (the date it finishes), in a global and I have managed to specify that they are only shown if the special_end is greater than now(). However, I would also like to use this in a template and it doesn't seem to be working.

<%if Special_End < NOW()%><%else%><%if Special%><%Special%><%endif%><%endif%>

I'm assuming that the problem is that I can't use NOW() in a template. Is there any other way to do this?

Thanks,

Laura.

Last edited by:

afinlr: Jun 10, 2002, 9:13 AM
Quote Reply
Re: [afinlr] Only show if date is greater than NOW() In reply to
Why can't the now() be incorporated into you global?


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Only show if date is greater than NOW() In reply to
Hi Ian,

I am using it in my global and it is working fine. The global shows all the special offers on one page and only shows them if they are still valid.

However, I would also like to use it in the link template so that the special offer is shown below the link if the special offer is valid. At the moment all special offers are shown even if they are past their end date.

Thanks, Laura.
Quote Reply
Re: [afinlr] Only show if date is greater than NOW() In reply to
Finally figured it out - I thought that it would be possible to compare dates but it seems not, so I converted them to numbers in a global and found the difference:

sub {
my $tags = shift;
Links::init_date();
my $date = GT::Date::date_get();
$date =~ s/-//g;
my $specialend = $tags->{Special_End};
$specialend =~ s/-//g;
my $diff = $date - $specialend;
return $diff;
}

Now I can use this in the template to only show special offers where the diff is less than zero.
The UK High Street
Quote Reply
Re: [afinlr] Only show if date is greater than NOW() In reply to
Hi ,

For some reason I did not get mail when you replied to me... I was not ignoring this thread on purposeBlush.

Glad you worked it out though.

I could have sworn that Links has an inbuilt date compare function where you can quickly and easily get the difference between two dates. Maybe someone could enlighten us on this?


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Only show if date is greater than NOW() In reply to
Hi,

Here, as a modest and hesitant programmer, is my suggestion. Using DBMan SQL, I have a database with records that need to be flagged as new if published in the last few (3) days.

Publication date column is named PubDate.
In my template, the test is:
<%if expiryflag%>...(show it's new)... <%endif%>

and my global is following:

<%expiryflag%>

sub {
# Returns flag 1 if expirydate has not passed,
# ie. less than today's date
# Otherwise flag is 0.
# Expirydate is my PubDate + an adjustable increment (ex. 3).
use GT::Date qw/:all/;
my $tags = shift;
my $today = GT::Date::date_get();
my $datepub = $tags->{DatePub};
my $expirydate = GT::Date::date_add($datepub,3);
my $flag = GT::Date::date_is_smaller($today, $expirydate);
return $flag;
}

It appears to work but I'd welcome any criticism and advice.
Cheers!
Charly

Last edited by:

charly: Jul 28, 2002, 1:38 AM
Quote Reply
Re: [charly] Only show if date is greater than NOW() In reply to
Hi Charly,

Thanks, that looks much neater. I'll give it a try.

Laura.
The UK High Street