Thread Datumsabstand berechnen (15 answers)
Opened by geloescht at 2012-09-29 13:44

geloescht
 2012-09-29 13:44
#162188 #162188
User since
2012-06-19
141 Artikel
BenutzerIn
[default_avatar]
Mahlzeit Forum

Eine doch simple Frage, die auf den zweiten Blick gar nicht so simpel ist.
Ich hab in einer CSV-DB in einer Spalte folgende Werte stehen(z.B):

Code: (dl )
1
2
3
4
statusdatum:
20110930
20110929
20110928


Das heutige Datum wäre:

Code: (dl )
20120929


Beim Heraussuchen aus der DB sollen aus dem oberen Beispiel die Zeilen 2 und 3 matchen. Das heisst Datumswerte die ein Jahr (Zeile 2) oder länder (Zeile 3) zurück liegen sollen einen Treffer ergeben. Datumswerte die noch nicht ein Jahr zurück liegen keine Treffer (Zeile 1).

Mein momentaner Denkansatz:

Ich splitte das Datum in $statusdatum nach 4 Stellen, und 2 und 2 Stellen:
20110929 => 2011 u. 09 u. 29
In die Skalare:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
my $yearcheck = ""
my $monthcheck = ""
my $daycheck = ""

$yearsplitt = substr($statusdatum,0,3); # 2011
$monthsplitt = substr($statusdatum,4,5); # 09
$daysplitt = substr($statusdatum,6,7); # 29

if ($yearsplitt < $yeartoday) {$yearcheck = 1;}
if ($monthsplitt <= $monthtoday) {$monthcheck = 1;}
if ($daysplitt <= $daytoday) {$daycheck = 1;}

if ($yearcheck = 1 and $monthcheck = 1 and $daycheck = 1) {Treffer}


Allerdings müsste ich ja dann die gesammte Spalte "statusdatum" in ein Array einlesen, und das Array nach und nach abklopfen?

Wie checkt Ihr Datumsabstände in einer DB. Gibt es da Module für oder geht es noch ganz anders?

Gruss HP-User
Last edited: 2012-09-29 13:47:50 +0200 (CEST)
Past brought us "SYS 64738". Present brought us "ctrl+alt+del". But what will future bring?

View full thread Datumsabstand berechnen