
perlpopper
New User
Oct 3, 2013, 3:16 PM
Post #1 of 2
(2192 views)
|
counting days using perl.
|
Can't Post
|
|
Hi guys, very new to perl and I suck Im trying to right a program that seems simple but my mind just cant get it right. I want to count the days between 2 dates without any modules, I have seen the modules do it pretty easily.. but I cant do it manually!! here is a bit of code to give an idea of what I am talking about.
print "birthDay: "; my $day = <STDIN>; print "birthMonth: "; my $month = <STDIN>; print "birthYear: "; my $year = <STDIN>; print "toDay: "; my $today = <STDIN>; print "Month: "; my $thismonth = <STDIN>; print "Year: "; my $thisyear = <STDIN>; my$daysCount=0; if ($year >$thisyear){ warn "Birth Year is after this year.???"; } #here is my problem, i want it to be full years e.g 365 days apart not just #1 date says 2012 and the next says 2013 elsif ($year == $thisyear){ $daysCount= NumberOfDaysBetween($day $today ,$month,$thisyear ); } sub DaysBetween { my$daysBetween=0; my$startDay=shift; my$endDay=shift; my$startMon =shift; my$endMon =shift; if $startMon == $endMon && $startDay<= $endDay){ $daysBetween = $endDay- $startDay; } else { $daysBetween =(($startDay-1)-(amountOfDaysInMonths($startMon ))) + $endDay + &seriesOfDaysInMonths$startMon, $endMon ); } } return $daysBetween; } #I dont have the data for the other sub routines available right now- but take it as they are ok. #my main concern is trying to undertsand the idea of having the full year in the above sub routine. so just incase it is not clear enough in the code statements. I want to amount to an actual year in the problem I stated in the code because right now I only have it as if year==this year but obviously years could be different and not actually be a full year apart e.g. dec-2001 & jan 2002 are not a year apart. Cant get the idea of how to code that.
|