Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: DIfference in days hours and second between dates

by davido (Archbishop)
on Jun 13, 2013 at 15:56 UTC ( #1038781=note: print w/replies, xml ) Need Help??

in reply to DIfference in days hours and second between dates

print timeDiff('', "2013-06-13 0:01:01", "2013-07-03 00:00:00" ), "\n"; gives me the following output:

19 J 23 H 58 M 59 Sec

Which, while I'm not sure it's 100% accurate, it's far from 734581 days. Have you tried printing the variables you're passing as parameters immediately before calling the function? Could be a case of garbage in.

....*sigh*..... This really ought to be relegated to DateTime, or one of the other CPAN offerings that is well maintained. Date calculations are not as easy as they look. What's with "local our" instead of true "my" variables? ...just curious; I don't see "local our", um, ever.


Replies are listed 'Best First'.
Re^2: local our
by space_monk (Chaplain) on Jun 13, 2013 at 16:08 UTC

    I think its because he's showing some old code he wrote, not new code. I mentioned the "local our" oddity in an earlier question of his on Re: perl variable displayed as a hash value.

    If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

      Yeah, I understand that it's old code. But "our" was introduced when, Perl 5.8 maybe? And "my" pretty much came with Perl 5. So where did the idiom come from? What book, what website, what teacher is promoting it? The idea came from somewhere, or a misinterpretation of an idea that came from somewhere. ;)

      It would never have been considered a "best practice" for variables that need to be lexically scoped to a subroutine in any version of Perl since Perl 5.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038781]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2018-02-24 22:47 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (311 votes). Check out past polls.