今日の日付をもとに、何日かプラスまたはマイナスした日付を出力するPerlスクリプトです。
例)前日の日付を出力する
“calc_date.pl -1”
▼calc_date.pl
#!/usr/bin/perl
#
# print the date of calculated day
#
# by sensaba.net 2003.2.5
#
if ($ARGV[0]) {
$day_plus = $ARGV[0];
} else {
$day_plus = 0;
}
$calc_time = time + $day_plus * 24*60*60;
$calc_date_string = &get_date_string($calc_time);
print $calc_date_string.”\n”;
sub get_date_string {
local $result;
local ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(pop(@_));
$year = $year + 1900;
$mon = $mon + 1;
$result = sprintf(“%.4d%.2d%.2d”, $year, $mon, $mday);
return $result;
}
#
# print the date of calculated day
#
# by sensaba.net 2003.2.5
#
if ($ARGV[0]) {
$day_plus = $ARGV[0];
} else {
$day_plus = 0;
}
$calc_time = time + $day_plus * 24*60*60;
$calc_date_string = &get_date_string($calc_time);
print $calc_date_string.”\n”;
sub get_date_string {
local $result;
local ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(pop(@_));
$year = $year + 1900;
$mon = $mon + 1;
$result = sprintf(“%.4d%.2d%.2d”, $year, $mon, $mday);
return $result;
}