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
What format do I use for Date/Time when writing to an XML file using
I want to use the DateTime.TryParse method to get the datetime value of a
I need to use a datetime.strptime on the text which looks like follows. Some
We use a base entity with properties such as version (datetime needed for NHibernate)
When I use the XML serializer to serialize a DateTime , it is written
How can I use .NET DataSet.Select method to search records that match a DateTime?
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
How do I use current date & time as the value for the findValue
Use case: A does something on his box and gots stuck. He asks B

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.