Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 629
  • Last Modified:

How can I do DATEADD in Perl?

I have a datetime object in Perl from MySQL database.  I want to Add x hours on this time and remove the minute and second part.  How can I do this in Perl?  Thanks.
0
thomaszhwang
Asked:
thomaszhwang
  • 2
  • 2
2 Solutions
 
farzanjCommented:
use DateTime;

  $dt = DateTime->new(
      year       => 1964,
      month      => 10,
      day        => 16,
      hour       => 16,
      minute     => 12,
      second     => 47,
      nanosecond => 500000000,
      time_zone  => 'Asia/Taipei',
  );

$dt->add(hours => 5)->subtract(minutes => 12)->subtract(seconds => 15);

More details:
http://search.cpan.org/~drolsky/DateTime-0.74/lib/DateTime.pm
0
 
thomaszhwangAuthor Commented:
Thanks.

Also how can I get the Minutes and Seconds of a datetime object?
0
 
farzanjCommented:
$dt->minute()
$dt->second()
0
 
thomaszhwangAuthor Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now