Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 970381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:47:48+00:00 2026-05-16T02:47:48+00:00

use DateTime ; my $date = 2010-08-02 09:10:08; my $dt = DateTime->now( time_zone =>

  • 0
use DateTime ;

my $date = "2010-08-02 09:10:08";

my $dt = DateTime->now( time_zone => 'local' )->set_time_zone('floating');
print $dt->subtract_datetime($date);

It’s not working; what is the problem?

The error message is:

Can't call method "time_zone" without a package or object reference at
/opt/perl/perl5.12/lib/site_perl/5.12.0/x86_64-linux/DateTime.pm line 1338
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:47:49+00:00Added an answer on May 16, 2026 at 2:47 am

    You need to convert date strings into DateTime objects first, using a
    customized format or one of the many DateTime::Format::* libraries available.
    You’re using a format commonly used in databases, so I’ve selected the MySQL
    formatter (and then defined a custom duration formatter for the end result,
    copied from the examples in
    DateTime::Format::Duration):

    use DateTime;
    use DateTime::Format::MySQL;
    use DateTime::Format::Duration;
    
    my $date = "2010-08-02 09:10:08";
    
    my $dt1 = DateTime->now(time_zone => 'floating', formatter => 'DateTime::Format::MySQL');
    my $dt2 = DateTime::Format::MySQL->parse_datetime($date);
    
    my $duration = $dt1 - $dt2;
    my $format = DateTime::Format::Duration->new(
        pattern => '%Y years, %m months, %e days, %H hours, %M minutes, %S seconds'
    );
    print $format->format_duration($duration);
    
    # prints:
    # 0 years, 00 months, 0 days, 00 hours, 421 minutes, 03 seconds
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I use DateTime.Now I get the date and time from the server point
I need to use DateTime.now to grab the current date, and strip off the
I use date and datetime widget into my formular , but the default values
I use this to convert DateTime value into Date and then I add 00:00:00
I use Hibernate and I have a datetime in my MySQL database. Now I
I use this code from another question: private bool NthDayOfMonth(DateTime date, DayOfWeek dow, int
Use PHP and MySQL. In my table, there is date field (datetime) recorded by
I'd like to use date time format string (possibly UTC) which is understandable and
What format do I use for Date/Time when writing to an XML file using
I tried to use the DataTime in my entity class. Adding @Temporal(TemporalType.DATE) above the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.