Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Re: Date/time increment

Expand Messages
  • Paul Archer
    ... Sure you re going to get weird results--unless you decrement by one afterwards. But I m with Mike Dillinger: convert to epoch seconds and do your math on
    Message 1 of 5 , Feb 7, 2005
    • 0 Attachment
      > I already tried adding 1 to month and then using that in Add_Delta
      > but the result comes up as Apr 01. And the invalid date error comes
      > up when I use a date like Jan 28.
      > I realized that the error is because Add_Delta probably uses 1-12 and
      > like I've said above, incrementing month by 1 gives even weirder
      > results.
      >
      Sure you're going to get weird results--unless you decrement by one
      afterwards.
      But I'm with Mike Dillinger: convert to epoch seconds and do your math on
      that. There's less chance of a screwup. Keep in mind that that won't work if
      you're adding months, though.



      > --- In perl-beginner@yahoogroups.com, Paul Archer <tigger@i...> wrote:
      >> I tried your code, and instead of getting an invalid date error, I
      > got:
      >> Feb 29 00:05:09, which is worse, really.
      >> I thought that maybe it was because you weren't using
      > Add_Delta_YMDHMS, but
      >> changing to that got the same results.
      >>
      >> Ok, here's the problem: it looks like Date::Calc thinks the months
      > are
      >> numbered 1-12, while everything else (in Perl, anyway) assumes they
      > are
      >> numbered 0-11.
      >> Try adding 1 to your month before feeding it to Date::Calc, and
      > then
      >> subtracting 1 after you're done.
      >>
      >>
      >> 4:39pm, mprmkk wrote:
      >>
      >>>
      >>>
      >>> Hi,
      >>>
      >>> I have a timestamp field of the format
      >>> "Feb 28 23:55:09". I am trying to increment the time
      >>> using Perl by say 10 mins and get the result as "Mar
      >>> 01 00:05:09". Below is what I used but Add_Delta_DHMS
      >>> gives me an invalid date error.
      >>> Please note that the input time format is exactly as
      >>> mentioned above. I also DO NOT want to use Date::Manip.
      >>>
      >>> Any help in solving this greatly appreciated.
      >>>
      >>> use Date::Calc qw(Add_Delta_DHMS);
      >>> use Date::Format;
      >>> use Date::Parse;
      >>> $dt = 'Feb 28 23:55:09';
      >>> $Dd = 0;
      >>> $Dh = 0;
      >>> $Dm = 10;
      >>> $Ds = 0;
      >>> my ($ss,$mm,$hh,$day,$month) = strptime($dt);
      >>> $year = '2005';
      >>> ($year,$month,$day, $hh,$mm,$ss) =
      >>> Add_Delta_DHMS($year,$month,$day, $hh,$mm,$ss,
      >>> $Dd,$Dh,$Dm,$Ds);
      >>> @arr = ($ss, $mm, $hh, $day, $month);
      >>> print strftime("%b %d %H:%M:%S", @arr);
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>> Unsubscribing info is here:
      > http://help.yahoo.com/help/us/groups/groups-32.html
      >>> Yahoo! Groups Links
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>
      >> ----------------------------------------------
      >> "We Americans, we're a simple people...
      >> but piss us off, and we'll bomb your cities."
      >> --------------Robin Williams------------------
      >
      >
      >
      >
      >
      > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
      > Yahoo! Groups Links
      >
      >
      >
      >
      >
      >
      >

      ----------------------------------------------------------------
      As to Jesus of Nazareth...I think the system of Morals and his
      Religion, as he left them to us, the best the World ever saw
      or is likely to see; but I apprehend it has received various
      corrupting Changes, and I have, with most of the present
      Dissenters in England, some doubts as to his divinity.
      --------------------Benjamin Franklin---------------------------
    Your message has been successfully submitted and would be delivered to recipients shortly.