User since
2003-09-24
111
Artikel
BenutzerIn
Hallo an alle,
Folgendes hab ich:
die Kalenderwoche: z.B. 47
jetzt möchte ich das Anfangsdatum und das Enddatum herausbekommen,also für die Kalenderwoche 47 diesen Jahres:
17.11.2003 und 23.11.2003
Weis von euch jemand wie das gehen könnte?
Danke schon mal für eure Hilfe
User since
2003-08-04
7321
Artikel
ModeratorIn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use strict;
use Date::Calc qw(This_Year Week_of_Year);
my @month_max_days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
my $this_year = This_Year();
sub is_leapyear
{
my ($year) = @_;
if(!$year) { return "-1" }
if($year % 4 == 0) { $v = 1 }
if($year % 100 == 0) { $v = 0 }
if($year % 400 == 0) { $v = 1 }
return $v;
}
my $is_leapyear = is_leapyear($this_year);
my %weeks_of_year = ();
for my $month (0 .. scalar(@month_max_days) - 1)
{
my $week = 0;
my @dates = ();
my $date = "";
my $max_days = $month_max_days[$month];
$max_days += 1 if $month == 1 and $is_leapyear;
for my $day (0 .. $max_days-1)
{
($week, undef) = Week_of_Year($this_year, $month, $day);
unless(defines $weeks_of_year{$week})
{
$weeks_of_year{$week} = [];
}
$date = "$this_year.$month.$day";
push @{$weeks_of_year{$week}}, $date;
}
}
print join(", ", @{$weeks_of_year{47}});
ungetestet... :)\n\n
<!--EDIT|esskar|1069435210-->
User since
2003-09-24
111
Artikel
BenutzerIn
hmm versteh ich nicht,
hat das was mit meinem problem zu tun?
User since
2003-08-04
7321
Artikel
ModeratorIn
[quote=Andreas,21.11.2003, 18:18]hmm versteh ich nicht,
hat das was mit meinem problem zu tun?[/quote]
schon....
es ist nicht so einfach das datum zu berechnen...
deswegen berechne ich zu jedem möglichen datum in einem jahr alle kallenderwochen und merke mir diese...
User since
2003-08-04
2145
Artikel
ModeratorIn + EditorIn
Wenn schon Date::Calc, warum dann nicht gleich Monday_of_Week() statt dieser ganzen Berechnung?
User since
2003-08-04
7321
Artikel
ModeratorIn
[quote=Dubu,22.11.2003, 10:20]Wenn schon Date::Calc, warum dann nicht gleich Monday_of_Week() statt dieser ganzen Berechnung?[/quote]
keine ahnung! :)
User since
2003-08-15
692
Artikel
BenutzerIn
use Date::Calc qw(Date_to_Days Add_Delta_Days Monday_of_Week);
my $monday = Date_to_Days Monday_of_Week 47, 2003;
my $friday = $monday + 4;
for ($monday, $friday)
{
printf "%02d.%02d.%04d", reverse Add_Delta_Days 1, 1, 1, $_-1;
}
\n\n
<!--EDIT|steffenw|1069530549-->
$SIG{USER} = sub {love 'Perl' or die};