[NBLUG/talk] perl script to rename file with a julian date
troy
fryman at sonic.net
Tue Feb 3 16:11:00 PST 2004
Hi, Coop-
On Tue, Feb 03, 2004 at 03:46:10PM -0800, Dave Cooper wrote:
> Well I've been playing around, with no success...
>
> I have 2 files in a /dir
>
> fileA.rpt and fileB.rpt
>
> everynight @ 2000 I need to rename the files with the julian date as the
> extension....
There's a bunch of stuff in the Date::Calc module.
for instance, the date_to_days sub:
This function returns the (absolute) number of the day of the given
date, where counting starts at the 1st of January of the year 1 A.D.
I.e., ""Date_to_Days(1,1,1)"" returns "1", ""Date_to_Days(1,12,31)""
returns "365", ""Date_to_Days(2,1,1)"" returns "366",
""Date_to_Days(1998,5,1)"" returns "729510", and so on.
This is sometimes also referred to (not quite correctly) as the Julian
date (or day). This may cause confu- sion, because also the number of the day
in a year (from 1 to 365 or 366) is frequently called the "Julian date".
So something like:
use Date::Calc qw(Date_To_Days);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$now = Date_To_Days($year+1900, $mon+1, $mday);
Date::Calc is a pretty big hammer; you might also check the CPAN for something
more specific.
-troy
More information about the talk
mailing list