Guest GastHallo, ich habe zwei "Datums" und möchte herausfinden, ob dazwischen weniger als 4 Jahre liegen.
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
use strict; use warnings; my $date_ok = "nicht ok"; my $day_birth = "28"; my $month_birth = "12"; my $year_birth = "2009"; my $day_p_date = "28"; my $month_p_date = "11"; my $year_p_date = "2013"; if (($year_p_date-$year_birth) < 5) { if (($year_p_date-$year_birth) < 4) { $date_ok = 1; } else { if (($month_p_date - $month_birth) < 0) { $date_ok = 2; } else { if (($month_p_date - $month_birth) > 0) { $date_ok = "nicht ok .."; } else { if (($day_p_date-$day_birth) < 0) { $date_ok = 3; } } } } } print $date_ok;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
use strict; use warnings; my $date_ok = 0; my $day_birth = "28"; my $month_birth = "12"; my $year_birth = "2009"; my $day_p_date = "28"; my $month_p_date = "11"; my $year_p_date = "2013"; my $date_diff=sprintf('%04u%02u%02u',$year_p_date,$month_p_date,$day_p_date)-sprintf('%04u%02u%02u',$year_birth,$month_birth,$day_birth); $date_ok=1 if($date_diff > sprintf('%04u%02u%02u',4,0,0) and $date_diff <= sprintf('%04u%02u%02u',5,0,0)); print "$date_ok\n";