in reply to Add A Number of Days to Today's Date
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.
Good luck!#! /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";
P.S. Opera appears to add carriage returns by itself to these posts - so my apologies if this is mis-formatted.
|
|---|