You might try this ...
$ cat datediff.pl #!/usr/bin/perl -w use strict; use Time::JulianDay; use vars qw/ $opt_a $opt_b /; use Getopt::Std; my $dateA = "59:59:23:31:11:2002"; # 1 second before 2003 my $dateB = "00:00:00:01:00:2003"; # 2003 getopt( "a:b:"); if( $opt_a ) { $dateA = $opt_a; } if( $opt_b ) { $dateB = $opt_b; } print "dateA = $dateA\n"; print "dateB = $dateB\n"; my ($sec,$min,$hours,$mday,$month_0_to_11,$year) = split /:/, $dateA; print "($sec,$min,$hours,$mday,$month_0_to_11,$year)\n"; ### ssA is the seconds since JAN 1st 1970 for dateA my $ssA = jd_timelocal($sec,$min,$hours,$mday,$month_0_to_11,$year); print "seconds from Jan 1st 1970 to 1 second before 2003 = $ssA\n"; ($sec,$min,$hours,$mday,$month_0_to_11,$year) = split /:/, $dateB; print "($sec,$min,$hours,$mday,$month_0_to_11,$year)\n"; ### ssB is the seconds since JAN 1st 1970 for dateB my $ssB = jd_timelocal($sec,$min,$hours,$mday,$month_0_to_11,$year); print "number of seconds from Jan 1st 1970 to midnight 2003 = $ssB\n"; my $diff = $ssB - $ssA; print "The diffence in seconds between $dateB and $dateA = $diff\n";
Here's soe output ...
$ ./datediff.pl dateA = 59:59:23:31:11:2002 dateB = 00:00:00:01:00:2003 (59,59,23,31,11,2002) number of seconds from Jan 1st 1970 to 1 second before 2003 = 10414079 +99 (00,00,00,01,00,2003) number of seconds from Jan 1st 1970 to midnight 2003 = 1041408000 The diffence in seconds between 00:00:00:01:00:2003 and 59:59:23:31:11 +:2002 = 1

the module Time::JulianDay is very to install.

In reply to Re: 'Difference between two dates in a ss:mm:hh etc format?' by rbc
in thread 'Difference between two dates in a ss:mm:hh etc format?' by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.