Gossamer Forum
Quote Reply
GT::Date issue
For some reason when i try to increment a date variable it gets stuck on the last day of october. Just keeps repeating.

CODE:
#!/usr/bin/perl5
use strict;
use lib '/path to admin/cgi-bin/links/admin';
use Links qw/$IN/;
use CGI::Carp qw(fatalsToBrowser);
use GT::Date qw/:all/;
local $SIG{__DIE__} = \&Links::fatal;
Links::init('/path to admin/cgi-bin/links/admin');

print $IN->header();
my $duration = 60;
my $date = "2004-10-01";
for (my $i=0; $i < $duration; $i++) {
print "$date<br>";
$date = date_add($date, 1);

}
exit;

OUTPUT:
2004-10-25
2004-10-26
2004-10-27
2004-10-28
2004-10-29
2004-10-30
2004-10-31
2004-10-31
2004-10-31
2004-10-31
2004-10-31
2004-10-31

Any body know why it wont go past october? it doesnt doesnt work even if i change the year to 2005.

Thanks

Hagai
Quote Reply
Re: [hagai] GT::Date issue In reply to
Well i fixed it by using date_add_gm.

Can anyone tell me the difference between the two?

Hagai
Quote Reply
Re: [hagai] GT::Date issue In reply to
Hi,

Something like this should work;

Code:
my $duration = 60;
my $date = "2004-10-01";
for (my $i=0; $i < $duration; $i++) {
my $newdate = date_add($date, $i);
print "$newdate<br>";
}


You need to keep $date, and then assign it to $newdate, where you can add $i (xx number of days).

I'm 99% sure this code will work, as I've used it pretty extensivly recently =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] GT::Date issue In reply to
that 1% always comes back to hunt ya.
It works better but i still get 2004-10-31 twice
so the output looks like this.

19: 2004-10-29
20: 2004-10-30
21: 2004-10-31
22: 2004-10-31
23: 2004-11-01
24: 2004-11-02
25: 2004-11-03

Im outputting $i: $newdate so something is definitely weird. btw. if i use date_add_gm it solves the problem.

Any idea what the difference is between date_add and date_add_gm is?

hagai
Quote Reply
Re: [hagai] GT::Date issue In reply to
Interesting.. it may be a machine related problem, rather than the module (I use almost exactly the same code in several of my custom scripts/globals, so I know it does work).

Is this with LSQL 2.2.x or 2.99 beta? If its the latter, then that could be your problem. I havn't really played with 2.99 too much yet.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] GT::Date issue In reply to
Yeah i think it might be machine related aswell, ill try it on a different server later on.
Im developing this on 2.1.2 installation, my other server has 2.2.0 on it.

Hagai