Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How do I find difference between two timestamps?

by davorg (Chancellor)
on Nov 16, 2004 at 17:19 UTC ( [id://408174]=note: print w/replies, xml ) Need Help??


in reply to How do I find difference between two timestamps?

Pretty simple with the correct DateTime modules installed.

#!/usr/bin/perl use strict; use warnings; use DateTime::Format::Strptime; my $fmt = '%Y-%m-%dT%H:%M:%S.%3NZ'; my ($start, $end) = qw(2004-11-15T18:59:52.863Z 2004-11-15T19:09:52.972Z); my $parser = DateTime::Format::Strptime->new(pattern => $fmt); my $dt1 = $parser->parse_datetime($start) or die; my $dt2 = $parser->parse_datetime($end) or die; my $diff = $dt2 - $dt1; print $diff->hours, " hours\n"; print $diff->minutes, " minutes\n"; print $diff->seconds, " seconds\n"; print $diff->nanoseconds / 1e6, " milliseconds\n";
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://408174]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found