Gossamer Forum
Quote Reply
GT::Dates
If I have a date in the format yyyy-mm-dd. Is there a function in Dates.pm which will convert this into a number so that I can do a comparison ?
i.e I have two dates in the above format and I want to know if one is within 30 days of the other.
Quote Reply
Re: [davidnavigator] GT::Dates In reply to
Hi,

you could try something like;

<%global_name('date1','date2')%>

Code:
sub {

use GT::Date qw/date_diff/;
my $date1 = $_[0];
my $date2 = $_[1];

my $days_diff = date_diff($date1,$date2);

return "Days between $date1 and $date2 are $days_diff";

}

Untested, but should work :)

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] GT::Dates In reply to
Probably the longest follow up to a post, but I've just tried this and I can't get it to work. Any one any ideas, I'm sure I've probably done something stupid ?
The GT::Date::date_diff just seems to return a result of zero.
This is the code and this is the result I get "0 2006-05-31, 2005-07-11"

Code:

sub {
## pass the customer ID
use GT::Date qw/date_diff/;
my $customer_id = shift;
my $expiry_date = $DB->table('customers')->select( { cus_id => $customer_id}, ['cus_supportexpiry'])->fetchrow;
my $dates;
my $today = GT::Date::date_get();
($dates->{today_date},$dates->{today_time}) = split / / => $today;
my $temp_date = $dates->{today_date};
my $overdue = GT::Date::date_diff($temp_date,$expiry_date);
return qq|$overdue $expiry_date, $temp_date|;
Quote Reply
Re: [davidnavigator] GT::Dates In reply to
Hi David,

You probably need to set the date format first, so that GT::Date knows how to parse it. Try adding this right before the date_diff call:

Code:
local $GT::Date::DATE_FMT = '%yyyy%-%mm%-%dd%';

That should let GT::Date properly parse the date string.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] GT::Dates In reply to
Many thanks, all working now