Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Calculating Difference In Dates

by kcott (Archbishop)
on Jan 27, 2014 at 23:20 UTC ( [id://1072294]=note: print w/replies, xml ) Need Help??


in reply to Calculating Difference In Dates

G'day Bugz,

You can use the core modules Time::Piece and Time::Seconds:

#!/usr/bin/env perl -l use strict; use warnings; use Time::Piece; use Time::Seconds; my $date1 = "2014/01/25 23:11:14"; my $date2 = "2014/01/26 00:30:37"; my $format = '%Y/%m/%d %H:%M:%S'; my $t0 = Time::Piece->strptime($date1, $format); my $t1 = Time::Piece->strptime($date2, $format); my $diff = $t1 - $t0; my $mins = int $diff->minutes; my $secs = $diff - $mins * 60; print "Minutes: $mins"; print "Seconds: $secs";

Output:

Minutes: 79 Seconds: 23

-- Ken

Replies are listed 'Best First'.
Re^2: Calculating Difference In Dates
by Anonymous Monk on Jan 27, 2014 at 23:47 UTC
    Thank you Ken.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found