Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

How to add a day using Time::Piece

by bangor (Monk)
on Nov 20, 2014 at 03:09 UTC ( [id://1107858]=perlquestion: print w/replies, xml ) Need Help??

bangor has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to add a day to a date but can't get it to work - any ideas?
use Time::Piece; my $t = gmtime; print $t->ymd . "\n"; $t += ONE_DAY; print $t->ymd . "\n"; my $t2 = $t + ONE_DAY; print $t2->ymd . "\n"; prints... 2014-11-20 2014-11-20 2014-11-20

Replies are listed 'Best First'.
Re: How to add a day using Time::Piece
by Anonymous Monk on Nov 20, 2014 at 03:13 UTC
    Basic debugging checklist
    #!/usr/bin/perl -- use strict; use warnings; use Time::Piece; my $t = gmtime; print $t->ymd . "\n"; $t += ONE_DAY; print $t->ymd . "\n"; my $t2 = $t + ONE_DAY; print $t2->ymd . "\n"; __END__ Bareword "ONE_DAY" not allowed while "strict subs" in use at - line 8. Bareword "ONE_DAY" not allowed while "strict subs" in use at - line 10 +. Execution of - aborted due to compilation errors.
      Ah, thank you, as you say 'basic'. I thought that the constant ONE_DAY was from Time::Piece but it is in fact from Time::Seconds. Adding the line 'use Time::Seconds;' fixed it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1107858]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2026-03-17 00:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.