Spooky,
There are a bunch of perl modules for this type of thing. There is new school DateTime and there is old school Date::Manip. Then there is the roll your own school (untested).
#!/usr/bin/perl use strict; use warnings; use Time::Local; my $ts1 = '2000-01-01 00:00:00.000000'; my $ts2 = '2009-03-05 18:59:11.674653'; my $elapsed = time_diff($ts1, $ts2); sub time_diff { my ($ts1, $ts2) = @_; my ($yr1, $mon1, $day1, $hr1, $min1, $sec1) = unpack('A4xA2xA2xA2x +A2xA2', $ts1); --$mon1; my $micro = substr($ts1, 19); my $epoch1 = timelocal($sec1, $min1, $hr1, $day1, $mon1, $yr1); $epoch1 += $micro; my ($yr2, $mon2, $day2, $hr2, $min2, $sec2) = unpack('A4xA2xA2xA2x +A2xA2', $ts2); --$mon2; $micro = substr($ts2, 29); my $epoch2 = timelocal($sec2, $min2, $hr2, $day2, $mon2, $yr2); $epoch2 += $micro; return $epoch2 - $epoch1; }

Cheers - L~R


In reply to Re: date-time into seconds by Limbic~Region
in thread date-time into seconds by Spooky

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.