Home: Perl Programming Help: Beginner:
counting days using perl.

New User

Oct 3, 2013, 3:16 PM

Views: 2240
counting days using perl.

Hi guys, very new to perl and I suckUnsure 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>;


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$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.


Oct 3, 2013, 5:56 PM

Views: 2236
Re: [perlpopper] counting days using perl.

Hi perlpopper,
I think this question has already been asked in Perlmonks either by you or by another person that goes with a name scripter87.

Here is the link to the thread:http://www.perlmonks.org/?node_id=1056668

I will advice that you go through various advise given. Moreover, if you don't want to use any module you can still go through those module and see how what you wanted was handled.

(This post was edited by 2teez on Oct 3, 2013, 5:58 PM)