Gossamer Forum
Home : Products : DBMan SQL : Development, Plugins and Globals :

Question about GT::Date::date_is_greater

Quote Reply
Question about GT::Date::date_is_greater
I'm trying to do a global that checks if a date is in the future or not and returns true or false accordingly. For some reason, it's not working. Any advice would be greatly appreciated:

Code:
sub date_is_current {
#-------------------------------------------------------------------
# Check if a date is "current" (either today or in the future).
my($date) = @_;
my $today = GT::Date::date_get();
return GT::Date::date_is_greater($date, $today);
}


The way I'm calling it in my templates is:

<%if Dbsql::Custom::date_is_current($date_field)%>
Display the record
<%endif%>

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] Question about GT::Date::date_is_greater In reply to
Hi,

Are you sure $date_field is in the right format for GT::Date?

Jasper

http://www.bookings.org
Quote Reply
Re: [jaspercram] Question about GT::Date::date_is_greater In reply to
Thanks for the reply. The date field is formatted as yyyy-mm-dd, which is the default format for MySQL and for GT::Date, isn't it? The column type for that column is set as "date" as well...

Any other thoughts?

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] Question about GT::Date::date_is_greater In reply to
It seems your subroutine only returns true if $date_field is greater then today and false when $date_field is equal to today. If you want true for both today and later, you could do something like
Code:
return !Date::date_is_smaller( shift, GT::Date::date_get());

Jasper

http://www.bookings.org
Quote Reply
Re: [jaspercram] Question about GT::Date::date_is_greater In reply to
Thanks - you're right. However, for some reason this is returning false for dates in the future. Either that, or I'm not using it correctly in my templates, perhaps?

Here's what I've got in my Custom.pm file:

Code:
sub date_is_current {
#-------------------------------------------------------------------
# Check if a date is "current" (either today or in the future).
return !GT::Date::date_is_smaller(shift, GT::Date::date_get());
}

And in my search_results.html template I've got:

<%loop results%>
<%if Dbsql::Custom::date_is_current($event_date)%>
do the event listing
<%endif%>
<%endloop%>

But nothing's coming up, even though there are plenty of events in the table, and several have dates in the future... Can you see anything I'm doing wrong? Thanks again for all your help.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] Question about GT::Date::date_is_greater In reply to
Did you do other tests? Change the subroutine to
Code:
sub date_is_current {
#-------------------------------------------------------------------
# Check if a date is "current" (either today or in the future).
my $date = shift;
my $today = GT::Date::date_get();
my $current = GT::Date::date_is_smaller($date, $today) ? "no" : "yes";
return "<p>Date: '$date', today: '$today', current: '$current'</p>";
}
and change the template to
Code:
<%loop results%>
<%Dbsql::Custom::date_is_current($event_date)%>
<%endloop%>

What do you get then?

Jasper

http://www.bookings.org
Quote Reply
Re: [jaspercram] Question about GT::Date::date_is_greater In reply to
Very interesting - thanks for the suggestion! This works exactly how you'd expect - it returns a listing of all the event dates, and accurately identifies whether they are "current" or not by indicating "yes" or "no".

So what do you think? Is the problem in the way the template parser handles the other subroutine? Or am I referencing it incorrectly, perhaps? Any ideas?

Thanks!

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] Question about GT::Date::date_is_greater In reply to
Try something like
Code:
<%loop results%>
<%set current = Dbsql::Custom::date_is_current($event_date)%>
<%if current%>
do the event listing
<%endif%>
<%endloop%>

http://www.bookings.org
Quote Reply
Re: [jaspercram] Question about GT::Date::date_is_greater In reply to
SUCCESS! That worked. I guess it's just a question of template syntax. Thanks for all your help!

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [jaspercram] Question about GT::Date::date_is_greater In reply to
I think you can use the function directly within the "if" tag. You don't have to set the return value to a variable first.
Quote Reply
Re: [Paul] Question about GT::Date::date_is_greater In reply to
I thought so, too, although this experience seems to indicate otherwise...

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] Question about GT::Date::date_is_greater In reply to
Hi

How can I use this sub routine to select/show only records thatīs about 90 or 120 days new?

thanks

Fabio
Quote Reply
Re: [assombracao] Question about GT::Date::date_is_greater In reply to
The example code is below:

require GT::Date;
my $today = GT::Date::date_get();

my $results = $DB->table('table_name')->select(GT::SQL::Condition->new(
date_field => '<=' => $today,
date_field => '>=' => GT::Date::date_sub($today, 90)
))->fetchall_hashref;

Hope that helps.

TheStone.

B.
Quote Reply
Re: [TheStone] Question about GT::Date::date_is_greater In reply to
Hi

I didnīt get it, Unsure
Iīm not a programmer

let me explain better what i need

I need something or a sub to show that the record is outdated

so it will check if the record is 90 days old and have an variable like is outdated
the default user will not see any outdated record, but the owner of that record will be able to see and modify or delete these records

My templates are customized, but this part of showing if the record is or isnīt outdated I can do

I need the way to check if the record is outdated

thanks again