> -----Original Message----- > From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] > Sent: Thursday, October 02, 2003 4:42 AM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: RE: problem with date routine > > > perlwannabe <[EMAIL PROTECTED]> wrote: > : > : I have a relatively simple script that needs to get > : two separate dates, today's date, and yesterday's > : date. The dates are in mmddyy format. > : Here is the script: > : > : > : ################## BEGIN SCRIPT ################################ > : my ($mday, $mon, $year) = (localtime)[3..5]; > : my $datetoday = sprintf ("%02d%02d%02d", ++$mon, $mday, $year-100); > : > : print ("the value of datetoday is $datetoday\n"); > : > : > : my ($yesterdaymday, $yesterdaymon, $yesterdayyear) = > : (localtime)[3..5]; > : my $dateyesterday = sprintf ("%02d%02d%02d", ++$yesterdaymon, > : $yesterdaymday-1, $yesterdayyear-100); > : print ("the value of datetoday is $dateyesterday\n"); > : > : ################### END SCRIPT > ##################################### > > A couple of others have pointed out the errors > above and fixes. I'd like to introduce you to the > POSIX function 'strftime' and the perl variable > '$^T'. > One problem above involves testing very close > to midnight. It is unlikely, but possible for a > routine built on two calls to localtime() to return > the same date for today and yesterday. The first > call would need to be before midnight and the > second call would have to be after midnight. > Admittedly, this would be very uncommon, but > certainly possible.
Actually, more common when time changes. Best to create a new time using the current day, month, and year, with the hour set to 12, then do the +-86400 thing, then extract the new day, month, and year. Check out Time::Local to create the time variable. -Mark -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]