Datumsprobleme

Post Reply
Message
Author
Matze

Datumsprobleme

#1 Post by Matze »

Hallo alle zusammen.

Ich hab ein Problem mit meiner Datumsanzeige.
Ich hoffe ihr könnt mir helfen.
Das Datum wird falsch angezeigt,
wenn ich die Variable $heute aufrufe, wird es richtig angezeigt,
rufe ich allerdings $tag.$mon.$jar auf dann stimmt es wieder nicht.
ich brauch aber die einzelnen Variablen, ich hoff ihr könnt mir helfen.

Beispiel:
http://www.autonarren.de/cgi-bin/test3.cgi

Danke schonmal
Matze



hier ist das entsprechende cgi script (test3.cgi):

#! /usr/bin/perl -w

print "Content-Type: text/html ";

($sek, $min, $std, $tag, $mon, $jar) = localtime(time);
$sek=&null($sek);
$sek = &null($sek);
$min = &null($min);
$std = &null($std);
$tag = &null($tag);
$mon = &null(++$mon);

$jar = $jar + 1900;
$zeit=$tag.".".$mon.".".$jar." | ".$std.":".$min.":".$sek." Uhr";
$heute=$tag.".".$mon.".".$jar;


sub null
{ if(length($_[0])<2)
{ return "0".$_[0]; }
else
{ return $_[0]; }
}


$gebd=15;
$gebm=12;
$geby=1981;

$alt=$jar-$geby;
$alter=$alt;
if (($mon-$gebm)<0) {$alter=$alt-1;}
if (($mon=$gebm) and ($gebd<$tag)) {$alter=$alt;}
if (($mon=$gebm) and ($gebd=$tag)) {$alter=$alt;}
if (($mon=$gebm) and ($gebd>$tag)) {$alter=$alt-1;}


print qq~
<html>
<head>

</head>

<body>

<font color="#000000" face="Courier" size="3">
<p style="word-spacing: 0px; margin-top: 0px; margin-bottom: 0px">
Dollar heute: $heute
</p>

<p style="word-spacing: 0px; margin-top: 0px; margin-bottom: 0px">
Dollar tag, Dollar mon, Dollar jar: $tag.$mon.$jar
</p>

<p style="word-spacing: 0px; margin-top: 0px; margin-bottom: 0px">
Das Alter ist: $alter
</p>
</font>


</body>
</html>

~;

rattengift

Re: Datumsprobleme

#2 Post by rattengift »

könntest du nicht den code aufs wesentliche reduzieren? ich hab jedenfalls keine lust, mich durch seitenweise unformatierten code zu quälen, der nichts mit dem eigentlichen problem zu tun hat.
probiers mal hiermit: <a href="http://www.pl-forum.de/cgi-bin/UltraBoa ... 0&Session=" target="_blank"><!--auto-->http://www.pl-forum.de/cgi-bin/UltraBoa ... <!--auto-->

rattengift

Re: Datumsprobleme

#3 Post by rattengift »

weil du die monatsvariable später wieder auf den geburtsmonat setzt:

> if (($mon=$gebm) ...

du meintest wohl eher <font face="Courier New">$mon==$gebm</font><!--fixed--> (also den vergleich und nicht die zuweisung).

ausserdem solltest du dir mal das else-konstrukt anschauen. die altersberechnung kannst du damit erheblich übersichtlicher machen. bei interesse kann ich dir eine solche lösung posten.

Matze

Re: Datumsprobleme

#4 Post by Matze »

Danke dir.

Jetzt weis ich was ich falsch gemacht habe.
Nach den Änderungen hat alles funktioniert.

Danke.

Post Reply