Thread datum inkrementieren
(23 answers)
Opened by
paidopoieo
at 2006-07-28 01:13
User since 2005-12-02
96
Artikel
BenutzerIn
hallo leute,
Ich hab ein programm geschrieben, das mir ein datum im format z.b: 2004/11/23 einliest, zu diesem datum 14 tage dazuzaehlt und anschliessend das datum wieder im selben format in das file rausschreibt.
es funktioniert bis auf ein paar kleinigkeiten: mit dem switch vom monat 12 auf 1 komm ich nicht ganz klar, und es sollte wenn tag und monat <= 10 sind einen nuller anfuegen, das macht es jedoch immer, so bekomm ich formate wie z.b: 2005/011/016
script:
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#!/usr/local/bin/perl -w
use Time::Local;
open(DAT,"datum.txt"); while(<DAT>) { $last_Date_Search = $_; } close DAT; print $last_Date_Search;
#assign date from file to $last_date my $last_date = $last_Date_Search;
#split date in 2005 and 11 and 01 after / => month 12 = 11, counts from 0..11 my @array_date = split /\//,$last_date;
if ($array_date[1] == 12) { $array_date[1] = $array_date[1] - 1; } #day month &nbs p; year my $dpe = timelocal(0,0,0,$array_date[2],$array_date[1],$array_date[0]);
print $dpe, "\n";
#add 14 days to $dpe => 14 days in seconds: 1209600 my $new_date_Search_seconds = $dpe + 1209600; print $new_date_Search_seconds, "\n";
(my $sec,my $min,my $hours,my $mday,my $month,my $year,my $wday,my $yday, my $st)=localtime($new_date_Search_seconds);
print $mday, "\n"; print $month, "\n"; print $year, "\n";
if ($month == 00) { $month = 12; }
my $new_year = $year + 1900;
if (($mday <= 9) || ($month <= 9)) { print $new_year,"/0",$month,"/0",$mday, "\n"; open(DAT,">datum.txt"); print DAT $new_year ,"/0", $month, "/0", $mday, "\n"; close DAT; } else { print $new_year ,"/", $month, "/", $mday, "\n"; open(DAT,">datum.txt"); print DAT $new_year ,"/", $month, "/", $mday, "\n"; close DAT;
}
danke fuer die hilfe.....
View full thread datum inkrementieren
|