Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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
Node Status?
node history
Node Type: note [id://320684]
[LanX]: the new BS Galactica series is my all time SoapFiction favourite ...
[Your Mother]: I even liked "The Arrival" and I generally hate time travel (oriented) stuff.
[Your Mother]: Gotta go. Stay out of trouble.
[LanX]: no worries ... mainland Europe is safe ;-P
[LanX]: ??? (probably my English is to limited)
[LanX]: too

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2018-03-19 15:12 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.