Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Adding to dates

by simeon2000 (Monk)
on Aug 08, 2002 at 13:15 UTC ( [id://188582]=note: print w/replies, xml ) Need Help??

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/"

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__

      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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://188582]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-06-20 18:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.