Solved

Time culculation

Posted on 2002-06-01
7
238 Views
Last Modified: 2010-08-05
Are there simple way to calculate number days passed after certain date.
E.g. after May 11 1955
0
Comment
Question by:desktop2
  • 3
  • 3
7 Comments
 
LVL 10

Expert Comment

by:rj2
ID: 7049308
#!/usr/bin/perl
use Date::Calc qw( Date_to_Days );
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print "Days: ",Date_to_Days($year+1900,$mon,$mday) - Date_to_Days(1955,5,11);

0
 
LVL 10

Expert Comment

by:rj2
ID: 7049310
There should be a "+1" on the month

#!/usr/bin/perl
use Date::Calc qw( Date_to_Days );
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print "Days: ",Date_to_Days($year+1900,$mon+1,$mday) - Date_to_Days(1955,5,11);

0
 

Author Comment

by:desktop2
ID: 7049476
Got an error :-(

Can't locate Date/Calc.pm in @INC (@INC contains: /usr/lib/perl5/i386-linux/5.00405 /usr/lib/perl5 /usr/lib/perl5/site_perl/i386-linux /usr/lib/perl5/site_perl .)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:rj2
ID: 7049581
Download and install the module Date::Calc

http://www.cpan.org/authors/id/STBEY/Date-Calc-5.0.tar.gz

Check this link for info if you don't know to install module from CPAN

http://www.perldoc.com/perl5.6.1/pod/perlfaq8.html#How-do-I-install-a-module-from-CPAN-
0
 

Author Comment

by:desktop2
ID: 7052439
I have a problem to install the module since this script is running on remote service where I do not have access. Is it possible to do it without additional module?
0
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 7053386
sub jd {
    use integer;
    my($y,$m,$d) = @_;
    return ( 1461 * ( $y + 4800 + ( $m - 14 ) / 12 ) ) / 4 +
    ( 367 * ($m - 2 - 12 * ( ( $m - 14 ) / 12 ) ) ) / 12 -
    ( 3 * ( ( $y + 4900 + ( $m - 14 ) / 12 ) / 100 ) ) / 4 +
    $d - 32075;
}
my ($m,$d,$y) = (${{Jan=>1,Feb=>2,Mar=>3,Apr=>4,May=>5,Jun=>6,Jul=>7,Aug=>8,Sep=>9,Oct=>10,Nov=>11,Dec=>12}}{May},11,1955);
my $jd0 = jd($y,$m,$d);
($y,$m,$d) = (localtime)[5,4,3];
my $jd1 = jd(1900+$y,1+$m,$d);
print $jd1-$jd0,"\n";
0
 

Author Comment

by:desktop2
ID: 7060915
It is working
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now