(I've also posted this in a more specific thread, but the question has become more general).
How can I make a subroutine that functions just like sub get_date, but always returns yesterday's date in the correct format?
Here's what I've tried- this works TODAY, but I'm afraid it will soon break, for example on the 1st of a month. Someone who knows perl better than I should be able to answer this!
sub get_yesterday {
#------------------------------------------------------------
# Returns yesterdays date in proper format
#
my ($time) = $_[0];
($time) or ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
$day=$day-1;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}
John
How can I make a subroutine that functions just like sub get_date, but always returns yesterday's date in the correct format?
Here's what I've tried- this works TODAY, but I'm afraid it will soon break, for example on the 1st of a month. Someone who knows perl better than I should be able to answer this!
sub get_yesterday {
#------------------------------------------------------------
# Returns yesterdays date in proper format
#
my ($time) = $_[0];
($time) or ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
$day=$day-1;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}
John