Ok... Here's an ugly hack that works in Perl 4. I don't know what if it's sufficient for your needs but I got curious and hacked away. It will fail in the year 2100, but you can work in the additional logic to handle the leap year exceptions.... God hopefully, this kludge won't be around in 96 years. Anyway, the main part is the function I called "diffTime" that returns the number of seconds since the supplied date and time. It returns a negative value for past dates and positive values for future dates. It only works with dates after 1970 and times must be in 24 hour format. Curious to know if this is at all useful to you.

Synopsis: &diffTime(3/10/2004 02:28:00)

-Aaron Greenberg
ahg at pobox dot com

#!/usr/local/bin/perl4 # Global config option for hours off of GMT. i.e. EST is -5. # NOTE: You may want to use something like 4.5 to average when Dayligh +t # savings time is in affect. $GMToffset = -5; # We Run from the commandline as sample program $diff = &diffTime($ARGV[0], $ARGV[1]); print "Diff Seconds: $diff\n"; $diffDays = $diff/(3600*24); print "Diff Days: $diffDays\n"; if ($diffDays < -16) { ### NOTE that it's negative for past days. print "\n*** Windows up for more than 16 days!\n"; } exit(0); # FUNCTION: diffTime (date time) # Usage &difftime( DD/MM/YYYY [HH:MM:SS] ) # A hyphen may be used as the date separator. only colons valid for ti +me # Returns seconds from current time. Negative for past events Posotiv +e for # future events. sub diffTime { local($rebootDate, $rebootTime, $rDmon, $rDday, $rDyear, $rDhour, $ +rDmin, $rDsec); local(@monthdays); local($sec, $leapCount, $i, $time); $rebootDate = $_[0]; # First Argument $rebootTime = $_[1]; # Second Argument unless (($rDmon, $rDday, $rDyear) = $rebootDate =~ /(\d{1,2})[\/-]{ +1}(\d{1,2})[\/-]{1}(\d{4})/) { print STDERR "Invalid Date\n\n"; exit(1); } @monthdays=(31,28,31,30,31,30,31,31,30,31,30,31); ### NOTE: This will break in the year 2100 if ($rDyear%4 == 0) { $monthdays[2]=29; } $sec = ($rDyear - 1970 ) * 365 * 24 * 60 * 60; $leapCount = int(($rDyear - 1972) / 4); $sec = $sec + ($leapCount * 24 * 60 * 60); for ( $i = $rDmon-2; $i >= 0; $i--) { $sec = $sec + ( $monthdays[$i] * 24 * 60 * 60); } $sec = $sec + ($rDday * 24 * 60 * 60); if ($rebootTime) { unless (($rDhour, $rDmin, $rDsec) = $rebootTime =~ /(\d{1,2})[:] +{1}(\d{1,2})[:]{1}(\d{1,2})/) { print STDERR "Invalid Time\n\n"; exit(2); } $sec = $sec + ($rDhour * 3600) + ($rDmin * 60) + $rDsec; } unless ($GMToffset) { $GMToffset = 0; } $time = time() + $GMToffset * 60 * 60; return $sec - $time; }


In reply to Re: Need Advice: Date difference revisted by Anonymous Monk
in thread Need Advice: Date difference revisted by emilford

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.