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
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):