Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

substract from actual date 7 days and printout in month.days.hours.min.year

by nicopelle (Acolyte)
on Mar 23, 2015 at 10:06 UTC ( [id://1120952]=perlquestion: print w/replies, xml ) Need Help??

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

Hi to all, I need to substract from actual date/time 7 days. The format could be for example #031810002015 (march 18 10:00 of year 2015):
#!/usr/bin/perl -w #output as 031810002015 (march 18 10:00 del 2015) ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); my $now = sprintf("%02d%02d%02d%02d%04d", $mon+1, $mday,$hour, $min,$y +ear+1900); print "$now\n";
Thanks for your time as usuals, Nick.
  • Comment on substract from actual date 7 days and printout in month.days.hours.min.year
  • Download Code

Replies are listed 'Best First'.
Re: substract from actual date 7 days and printout in month.days.hours.min.year
by Anonymous Monk on Mar 23, 2015 at 10:29 UTC

    Use one of the modules available on CPAN, some examples are Date::Calc, Date::Manip, or DateTime.

    use DateTime; print DateTime->now->add(days=>-7) ->strftime('%m%d%H%M%Y'), "\n"; __END__ 031614272015
      Thanks to everyone has replied this post. Thanks to all, Nick.
Re: substract from actual date 7 days ..
by Discipulus (Canon) on Mar 23, 2015 at 10:29 UTC
    Hello nicopelle,
    You have many options to do this: see this node to review them (production code must use serious modules..)
    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: substract from actual date 7 days and printout in month.days.hours.min.year
by MidLifeXis (Monsignor) on Mar 23, 2015 at 13:34 UTC

    Do you mean 7 days, 7*24*60*60 seconds, or something else? Think daylight savings time boundaries, leap seconds, etc.

    --MidLifeXis

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found