Gossamer Forum
Home : General : Perl Programming :

listing dates

Quote Reply
listing dates
i'm sorting records by date so i have a heading that is the date and then list the records matching that date, then on to the next date. now what i would like to do is list missing dates that fall on a certain day of the week. here's what it looks like now

unless ($last_category eq $rec{'Vol_date'}) {
print qq|<td colspan=$numcols><h2>$dow $rec{'Vol_date'}</h2></td></tr><tr>|;
$last_category = $rec{'Vol_date'};
}
now it prints the record
gets another record and starts over (compares last category to vol_date)

i want it to print all fridays and saturdays whether there's a record or not. if there's no record for a friday or saturday, i want it to print "no record" and then go on to the next friday or saturday.

my code is so messed up i don't even want to post what i have. pls help! tks
Quote Reply
Re: [delicia] listing dates In reply to
Hi,

You many find this helps:

http://search.cpan.org/...lc/lib/Date/Calc.pod

Monday_of_Week

Then us Add_Delta_Days() to add 6 days to it (giving it the friday date)

Hope that helps.

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] listing dates In reply to
that looks like it handles anything i could ever want! unfortunately, i can't figure out how to use it. i tried putting use date::calc qw ( ); in my code, listing about 4 things i wanted to try out, like check_date and day of week. i get an error that it can't find date/calc. my hosting help says it supports most modules and to include require module.pl in my script. i'm not sure what to require. can you give me another pointer please. thanks.
Quote Reply
Re: [delicia] listing dates In reply to
Hi,

Sounds like they need to install Date::Calc. I'm sure it won't be a problem (as its a widely used perl module)

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] listing dates In reply to
host says i just need to put require ("module_name.pl"); in my code. what do i put for module_name ???
Quote Reply
Re: [delicia] listing dates In reply to
Nope - that won't make a difference. If this doesn't work:

Code:
use Date::Calc;

...thern that means the don't have it installed. Using that line they gave you won't make a difference if you get the error using "use" Wink

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] listing dates In reply to
i think i've found some code that will work but i'm still having trouble

Code:
$now_open = &date_to_unix($rec{'Vol_date'});
$now_dow = &get_day_of_week($rec{'Vol_date'});

if (!$next_open) { $next_open = $now_open; }

$next_dow = &get_day_of_week($next_open);
$next_yyyy = substr($next_open,0,4);
$next_mm = substr($next_open,4,2);
$next_dd = substr($next_open,6,2);

unless ($last_category eq $rec{'Vol_date'}) {

#while ( $now_open > $next_open) {
# print statements for testing
# print qq|<td colspan=$numcols><p>now $now_open $now_dow</p></td></tr><tr>|;
# print qq|<td colspan=$numcols><h2>next $next_open $next_dow</h2></td></tr><tr>|;
# print qq|<td colspan=$numcols><p>now $now_yyyy $now_mm $now_dd</p></td></tr><tr>|;
######## here's what i want to happen while $now_open > $next open
# print $next open as a heading
# print a dummy record
# increment next open to the next friday or saturday
#####

if (lc($next_dow) eq 'friday') {
($next_open_yyyy,$next_open_mm,$next_open_dd) = &getTomorrow($next_yyyy,$next_mm,$next_dd);
}
else { ($next_open_yyyy,$next_open_mm,$next_open_dd) = &getNextFri($next_yyyy,$next_mm,$next_dd); }
$next_open = $next_open_yyyy . $next_open_mm . $next_open_dd;
$next_dow = &get_day_of_week($next_open);
#} # end while


print qq|<td colspan=$numcols><h2>$now_dow $rec{'Vol_date'}</h2></td></tr><tr>|;
$last_category = $rec{'Vol_date'};
}
# now it prints the actual record and gets another

everytime i uncomment the while statement, it goes into a loop and runs forever. it must be something obvious that i'm overlooking.
Quote Reply
Re: [delicia] listing dates In reply to
You really do need to get Date::Calc setup - it makes everything so much easier ;)

Example:

http://ultradev.com.nmsrv.com/cgi-bin/test.cgi

This script gets the current date, then works out the friday after (i.e this coming friday) , and then goes through and adds the next 51 weeks worth of fridays to a list. Something similar should work perfeclty for what you want (but you just need to get your stuipid host to setup the module :/)

Code:
#!/usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);

print "Content-Type: text/html \n\n";

use Date::Calc;

my ($year,$month,$day) = Date::Calc::Today();

print qq|$day $month $year <br />|;

my $day_of_week = Date::Calc::Day_of_Week($year,$month,$day);

print qq|Day of week is: $day_of_week \n|; # sunday = 0
# monday = 1
# tuesday = 2
# wednesday = 3
# thursday = 4
# fridayy = 5 - the day we wanna get to
# saturday = 6

my $days_to_add;
if ($day_of_week == 0) {
$days_to_add = 5;
} elsif ($day_of_week == 1) {
$days_to_add = 4;
} elsif ($day_of_week == 2) {
$days_to_add = 3;
} elsif ($day_of_week == 3) {
$days_to_add = 2;
} elsif ($day_of_week == 4) {
$days_to_add = 1;
} elsif ($day_of_week == 5) {
$days_to_add = 0;
} elsif ($day_of_week == 6) {
$days_to_add = 6;
}

# ok, now lets add the number of days to TODAYs date...

my ($year,$month,$day) = Date::Calc::Add_Delta_Days($year,$month,$day, $days_to_add);

print qq|Fridays date is: $day $month $year <br />|;


# ok, now we have fridays date - lets populate a list of the next 51 weeks, and push into an array
my @dates;
push @dates, qq|${day}-${month}-${year}|;
for (my $i = 1; $i <= 52; $i++) {
my $days_to_add = $i * 7; # work out how many days to add to "today"
my ($year2,$month2,$day2) = Date::Calc::Add_Delta_Days($year,$month,$day, $days_to_add);
push @dates, qq|${day2}-${month2}-${year2}|;
}

use Data::Dumper;
print "<PRE>" . Dumper(@dates) . "</PRE>";

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] listing dates In reply to
i found some code i already had that did the date calculations. after starting over, i finally found my logic error in my while loop. so i have it working now. my host has perl 5.8. i notice the date calc is included with 5.10 so i guess they'll install it when they go to 5.10. thanks!