Gossamer Forum
Home : Products : Gossamer Links : Discussions :

GT::Date Usage Question

Quote Reply
GT::Date Usage Question
Hi,

I have these values:

$interval (interger in minutes)
$lastchange (date time in MySql format 00-00-00 00:00:00)

I want to do a simple if statement which check to see if the datetime now is greater than the $lastchange plus the interval... in other words , has the required time gone by since the last change.

My problem is in the actual usage of the GT::Date to accomplish this. And, should I initialise the date function first? "Links::init_date();"

I understand the date_diff function is working in days, not seconds, so I guess this would have to be converted.

if ( date_diff() ) {

}


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] GT::Date Usage Question In reply to
Hi,

Try:

Link::init_date();
my $lastchange_sec = GT::Date::timelocal(GT::Date::parse_format($lastchange));
if (time > ($lastchange_sec + $interval)) {
# true
}

should work. parse_format() takes a string and returns a localtime() array. timelocal() takes a localtime() array and returns unix seconds.

I really wish I had never used sql dates for Links SQL, always use int's and store seconds. It's so much easier to work with. =)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] GT::Date Usage Question In reply to
Hi Alex,

That looks good and I think I understand the format.

I guess I should also change my $interval to seconds for this to work.

Thanks,

Ian


Code:
my $interval = $st->select('TrendInterval')->fetchrow_array;
my $lastchange = $st->select('LastChange')->fetchrow_array;
$interval = $interval * 60;
Links::init_date();
my $lastchange_sec = GT::Date::timelocal(GT::Date::parse_format($lastchange));
if (time > ($lastchange_sec + $interval)) {
# true
}


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jul 5, 2002, 6:34 PM
Quote Reply
Re: [Alex] GT::Date Usage Question In reply to
Quote:
I really wish I had never used sql dates for Links SQL, always use int's and store seconds. It's so much easier to work with. =)
I do not understand, why you wish you had never uses sql dates. Using seconds base is difficulter to use. Also internal SQL functions can be used to compare SQL style dates.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] GT::Date Usage Question In reply to
>>
Using seconds base is difficulter to use.
<<

No it is more flexible.
Quote Reply
Re: [Paul] GT::Date Usage Question In reply to
A question:

Why does Add_Date in a detailed page come up nice (Wed Aug 28 2002), but in a say a category page it looks like " 2002-08-28 ". ???



I would like the <%Add_Date%> tag to work the same way everywhere, this is confusing Crazy
Quote Reply
Re: [Paul] GT::Date Usage Question In reply to
When I do work with my database, I often do check the results with an SQL client. So with second based dates, visual checking would be difficulter.

Otherwise, yes, if we have just a unix time (in seconds), it is easier to convert to any date. I aggree.
Also it has performance advantage.

However, I do prefer the current solution in LSQL. Having a definiable db date format to store and work with, and a definiable, changeable display date format, we use to display on the site.

So there are more viewpoints. And my personal opinion is, that current solution is good.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [nt6] GT::Date Usage Question In reply to
You can change it by setting the format GT::Date uses with a global tag at the top of your page.

<%set_date_format%>

Code:
sub {
require GT::Date;
import GT::Date qw/date_set_format/;
date_set_format('%ddd% %mmm% %dd% %yyyy%');
return;
}

I think that should work.

Last edited by:

Paul: Aug 30, 2002, 6:30 AM
Quote Reply
Re: [Paul] GT::Date Usage Question In reply to
Thank you Paul.

I just added the global and the tag in the template on my category page, but <%Add_date%> still comes out as " 2002-08-28 " on that page.
Quote Reply
Re: [nt6] GT::Date Usage Question In reply to
Oh sorry that is produced by the tag in link.html right?

You'd have to pass $add_date into a global and reformat it. Something like:

<%reformat_date($add_date)%>
Quote Reply
Re: [Paul] GT::Date Usage Question In reply to
Paul I appreciate your support. I am still stick right here:

I got the <%set_date_format%> tag at the top of my links.html page.

I also have <%set_date_format($add_date)%> where I would like the the <%Add_date%> to display correctly.

I even tried changing your "$add_date" to "$Add_date" (the proper tag is "<%Add_date%> with a capital A) but it still doesn't display anything. Have I done something wrong?
Quote Reply
Re: [nt6] GT::Date Usage Question In reply to
hello every one, i have some problem as nt6,

links show me 2003-09-30 all time at my top links global.

sub {
#Top 10 sites by hits.
my ($output,$sth,$link);
my $id = shift;
my $db = $DB->table ('Links');
$db->select_options ('ORDER BY ADD_DATE DESC', 'LIMIT 5');
my $sth = $db->select ( { isValidated => 'Yes'} );
my $premium;
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link1', $link);
}
return $output;
}



please help to change date format.
Quote Reply
Re: [romanslon] GT::Date Usage Question In reply to
Are your links really ordered correctly? I think that Add_Date shouldn't be in capital letters in your order by statement.

sub {
#Top 10 sites by hits.

use GT::Date;
my ($output,$sth,$link);
my $id = shift;
my $db = $DB->table ('Links');
$db->select_options ('ORDER BY Add_Date DESC', 'LIMIT 5');
my $sth = $db->select ( { isValidated => 'Yes'} );

while ($link = $sth->fetchrow_hashref) {
$link->{Add_Date}=GT::Date::date_transform($link->{Add_Date},"%yyyy%-%mm%-%dd%","%dd% %mmm% %yyyy%");

$output .= Links::SiteHTML::display ('link1', $link);
}
return $output;
}
Quote Reply
Re: [afinlr] GT::Date Usage Question In reply to
thanks!

its working now.Laugh