Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Re: Determining time since

by l2kashe (Deacon)
on Jan 12, 2004 at 15:45 UTC ( #320684=note: print w/replies, xml ) Need Help??

in reply to Re: Determining time since
in thread Determining time since

Along the same lines, you could do something to the effect of

Update: After reading sulfericacid's response, I tested my algo. The issue was a typo ( popped up with use strict;), and I wasn't calling int. New code below.

#!/usr/bin/perl # tested and verified use strict; my $then = time() - (86400 * 3); my $min_s = 60; my $hour_s = $min_s * 60; my $day_s = $hour_s * 24; my $elapsed = time() - $then; my $output; my $days = int( $elapsed / $day_s ); $elapsed -= $days * $day_s; $output = "$days days " if $days; my $hours = int ( $elapsed / $hour_s ); $elapsed -= $hours * $hour_s; $output .= "$hours hours " if $hours; my $mins = int ( $elapsed / $min_s ); $elapsed -= $mins * $min_s; $output .= "$mins minutes " if $mins; $output .= "$elapsed seconds" if $elapsed; # so on and so forth; print "$output ago\n";

use perl;
Everyone should spend some time pounding nails with their forehead for a while before they graduate to complicated stuff like hammers. - Dominus

Replies are listed 'Best First'.
Re: Re: Re: Determining time since
by sulfericacid (Deacon) on Jan 12, 2004 at 16:22 UTC
    I tried l2kashe's code and the test came out:
    0.00146257716049383 days 4.21062361931911e-18 hours ago
    I have no idea what went wrong, but I think you should go with a module on this one. Check out Time::Duration from It looks like it'll accomplish this for you.

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2022-08-17 16:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found