in reply to Comparing two dates and finding out number of days

I may be wrong here, but this sounds like a homework question, where the school's sysadmin won't allow you to install new modules ... The fact that you have not solved it at all (not even an approximate solution...) in about 1 week supports my suspicion. This is a classic homework problem in C/C++ programming courses, when they teach you about enums...

How about transforming both dates in days and finding the difference? Yes, you will need to account for leap years. How about finding the number of days till the end of the month of the first date, then the rest of the year, then add years until the second date, then add (days in the) months until the month number in the second date, then the few days left? Yes, you will also need to account for leap years too (multiple of 4, not of 100, but also multiple of 400). Sounds like an array there index i holds the number of days in that month (then you do the trick with the leap year verification).

Again, since I suspect this is homework, I will stop here and not post any code. This should help plenty I think.

  • Comment on Re: Comparing two dates and finding out number of days

Replies are listed 'Best First'.
Re^2: Comparing two dates and finding out number of days
by Ashes.cfg (Initiate) on Nov 15, 2007 at 16:56 UTC
    homework.Well I am well past homework stage. here is the deal. I am a telecommunications engineer and trying to learn how to script in perl as my manager wants me to write some scripts for him :) . I would never even ask fellow monks for code for my homework. i would love to just install Date::Simple and simplify my problem. I have tried even installing it but my PPM doesnt even detect it when i refresh. I dont know what the problem is. i used time::local and tried finding out diff between two dates in seconds but i dont know i am getting really weird answers. but i get what you said. I shall try tht..if not then God Help :)

      When all else fails install manually:

      1. download the tarball
      2. decompress it,
      3. cd to the directory created, something like Date-Simple-3.02,
      4. perl Makefile.PL will create a make file for you,
      5. make test will ensure that everything is working nicely,
      6. make all will install the module locally in the directory you are working in,
      7. The module will now be in the blib/lib directory; copy it to your development lib directory, use lib on that directory, and you can use Date::Simple.
      perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'
      I have tried even installing it but my PPM doesnt even detect it when i refresh.

      I personally believe you may want to add some repositories to your PPM's configuration.