Hi rline,

My approach differs a bit from what other's have posted here, so I'll offer it. I like to avoid modules that others might have to download, because I know first hand that process doesn't always go smoothly. So here is an example that accomplishes two things - first allows your user to specify a date (which are fed to $mday,$mon,$year) and a number of days (fed to $daysFromNow) and using the built-in Time::Local module will return th date you desire. Second it avoids having to specify non-standard modules, or having to manually getting date manipulation right.

The idea is the same as what the other monks are telling you, I just "like my way better(tm)". I also find it much safer than trusting my dumb brain to handle manipulating dates by hand.

#! /usr/local/bin/perl -w use strict; use Time::Local; my ($sec,$min,$hour,$mday,$mon,$year) = (0,0,0,22,11,2001); my $daysFromNow = 99; $year-=1900; $mon-=1; $daysFromNow*=86400; my $givenTime = timelocal($sec,$min,$hour,$mday,$mon,$year); $givenTime+=$daysFromNow; ($sec,$min,$hour,$mday,$mon,$year) = localtime($givenTime); $year+=1900;$mon+=1; print "$year-$mon-$mday $hour:$min:$sec\n";
Good luck!
{NULE}

P.S. Opera appears to add carriage returns by itself to these posts - so my apologies if this is mis-formatted.


In reply to Re: Add A Number of Days to Today's Date by {NULE}
in thread Add A Number of Days to Today's Date by rline

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.