bazz
11-18-2009, 12:46 AM
Hi,
I have a grid on my web page sort of like a calendar. left col is the room number and the next 31 or so cols to the right of it, are the dates I want to show. eg a whole month of up to 31 (as appropriate) or 31 days from say 15. could equally be 31 days from 28.
the values being passed to this scirpt are $year, $month, $date.
The following code gets me the number of days in a given month and then I loop through those as shown
#Days_in_Month
my $days = Days_in_Month($year,$month); # number of days this month
foreach my $day_number (1..$days)
{
# make single-digit numbers double-digit.
$day_number = sprintf("%02d", $day_number);
$month = sprintf("%02d", $month);
my $full_iso_date = "$year-$month-$day_number";
}
This obviously won't work for the scenario where 15 days are in one month and 15 days are in the next month. so would you recommend:
1. In place of 'Days_in_Month' I should convert to Day_of_Year and so they would be a consecutive range from say 15 thru 46
2. in the loop, I then convert back to the date of the month so I shall OUTPUT 15-31 followed by 1-16?
OR would you know a better way?
bazz
I have a grid on my web page sort of like a calendar. left col is the room number and the next 31 or so cols to the right of it, are the dates I want to show. eg a whole month of up to 31 (as appropriate) or 31 days from say 15. could equally be 31 days from 28.
the values being passed to this scirpt are $year, $month, $date.
The following code gets me the number of days in a given month and then I loop through those as shown
#Days_in_Month
my $days = Days_in_Month($year,$month); # number of days this month
foreach my $day_number (1..$days)
{
# make single-digit numbers double-digit.
$day_number = sprintf("%02d", $day_number);
$month = sprintf("%02d", $month);
my $full_iso_date = "$year-$month-$day_number";
}
This obviously won't work for the scenario where 15 days are in one month and 15 days are in the next month. so would you recommend:
1. In place of 'Days_in_Month' I should convert to Day_of_Year and so they would be a consecutive range from say 15 thru 46
2. in the loop, I then convert back to the date of the month so I shall OUTPUT 15-31 followed by 1-16?
OR would you know a better way?
bazz