CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



perlpopper
New User

Oct 3, 2013, 3:16 PM

Post #1 of 2 (717 views)
counting days using perl. Can't Post

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.

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


2teez
Novice

Oct 3, 2013, 5:56 PM

Post #2 of 2 (713 views)
Re: [perlpopper] counting days using perl. [In reply to] Can't Post

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)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives