Thread Datum: 1 des Monats minus 1Tag (10 answers)
Opened by dani at 2005-12-27 09:24

bloonix
 2005-12-27 15:56
#61375 #61375
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo dani,

deine Frage ist zwar schon beantwortet worden ...

Code (perl): (dl )
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
   # $nmb enthält die Anzahl Tage, die vom heutigen
   # Datum abgezogen werden sollen ...
   my $nmb = 374672;

   my @tm  = (localtime);
   $tm[5] += 1900;
   $tm[4]++;

   while ($nmb--) {
      $tm[3]--;
      if ($tm[3] == 0) {
         $tm[4]--;
         if ($tm[4] == 0) {
            $tm[4] = 12;
            $tm[5]--;
         }
         if ($tm[4] =~ /^(1|3|5|7|8|10|12)$/) {
            $tm[3] = 31;
         } elsif ($tm[4] =~ /^(4|6|9|11)$/) {
            $tm[3] = 30;

         # ein Schaltjahr ist ...
         # - wenn ein Jahr durch 4 teilbar ist
         # - aber nicht, wenn es durch 100 teilbar ist
         # - aber doch wieder, wenn es durch 400 teilbar ist

         } elsif (!($tm[5] % 400) || ($tm[5] % 100 && !($tm[5] % 4))) {
            $tm[3] = 29;
         } else {
            $tm[3] = 28;
         }
      }
   }


Das geht bestimmt auch leichter, aber so auch :)

Greez,
opi
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Datum: 1 des Monats minus 1Tag