http://www.perlmonks.org?node_id=188582


in reply to Adding to dates

This is really easy to do. Here:

# define the seconds in a week use constant WEEK => 60 * 60 * 24 * 7; my $now = time(); my $then = $now + WEEK * 2;

Or, to one-line it:

my $then = time() + 1209600;

--
perl -e "print qq/just another perl hacker who doesn't grok japh\n/"
simeon2000|http://holdren.net/

Replies are listed 'Best First'.
Re: Re: Adding to dates
by bobrobclob (Initiate) on Aug 08, 2002 at 14:34 UTC
    just tried your solution simeon and the ourtput from $then was 1030012664? I need the output to be in the form of YY-MM-DD Thanks

      So, just to expand a little on simeon2000's answer:

      #! /usr/bin/perl use strict ; use warnings ; $|++ ; use constant WEEK => 60 * 60 * 24 * 7 ; my @later = localtime( time + ( WEEK * 2 ) ) ; my $fmt_date = sprintf "%04d-%02d-%02d", $later[5] + 1900, $later[4], $later[3] ; print $fmt_date, "\n" ; __END__

      _______________
      DamnDirtyApe
      Those who know that they are profound strive for clarity. Those who
      would like to seem profound to the crowd strive for obscurity.
                  --Friedrich Nietzsche
Re: Re: Adding to dates
by bobrobclob (Initiate) on Aug 08, 2002 at 14:26 UTC
    sorry peeps, i wasn't descriptive enough. This is what i realy need to do: get the current date, add 14 days to it, format it to YYYY-MM-DD and then put it into a variable so that i can use it on a command like... adduser myself -e $expirydate