In the words and stile of a grateful man:-
Thank you, and thank you again.

I have made the changes that everybody kindly suggested
And thanks to all who noticed my incorrect calculations.
This steams from to points.
1st, i copied bits of the code of different help notes and tried to cobble it all together.
2nd, I'm honestly not sure how this code is working when it comes to the lines of
$months = int($diff->months); #i know int insure an integer.
In this case dumping the number of seconds that are left over?

$diff -= $months * ONE_MONTH; # but this line confuses me?

Where does the "ONE_MONTH" variable get pulled from?
ie how do i know if i got the right name?

is it lifted from the Time::Piece pm
ie this bit:
use constant 'c_sec' => 0;
use constant 'c_min' => 1;
use constant 'c_hour' => 2;
use constant 'c_mday' => 3;
use constant 'c_mon' => 4;
use constant 'c_year' => 5;
use constant 'c_wday' => 6;
use constant 'c_yday' => 7;
use constant 'c_isdst' => 8;
use constant 'c_epoch' => 9;
use constant 'c_islocal' => 10;

or is my understanding of this as closes to my understanding of rocket since.

One thing i using code and another understanding it :(

One final thing If I may. I have copy my final code below. Can anybody see any other faults I have missed/misunderstood?

Final I would like to thank again everybody who has help me understand this.

Regards,
Gareth

#!/usr/bin/perl use Time::Piece; use Time::Seconds; $before = Time::Piece->strptime("Thu Apr 1 10:00:00 2003", "%a %b %e % +H:%M:%S %Y"); $now = localtime(time) + $before->tzoffset; print "Time now is:$now\n"; # gives time format "Thu May 1 13:11:11 +2003" print "Time before:$before\n"; # gives time format of "Thu May 1 13:1 +1:11 2003" # (dont forget timezone) $diff = $now - $before; $years = int($diff->years); $diff -= $years * ONE_YEAR; $months = int($diff->months); $diff -= $months * ONE_MONTH; $days = int($diff->days); $diff -= $days * ONE_DAYS; $hours = int($diff->hours); $diff -= $hours * ONE_HOUR; $minutes = int($diff->minutes); $diff -= $minute * ONE_MINUTE; print "$years years, $months months, $days days, $hours hours, $minute +s minutes since $before\n";

In reply to Re: Re: More Help please ? Time::Piece errors? by spacey
in thread Time::Piece errors? by spacey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.