Date conversion script

J

Jon Carpenter

I need some help with a script I am writing. Maybe someone has some
experience with this. I need a part of the script to take a standard input,
a 3-digit ordinal date (e.g. 060), and convert it to the cardinal date,
assuming the current year (e.g. 20040229). I also need to be able to
convert parts of that string, the month, to the abbreviation (e.g. 02 to
FEB), and put the parts of that string in different places (e.g. *29*0000 -
*29*2359 *FEB* *2004*). This is for creating daily log reports.

Thanks in advance,
Jon
-Two wrongs don't make a right, but three lefts do.
 
J

Jack Challen

Jon said:
I need some help with a script I am writing. Maybe someone has some
experience with this. I need a part of the script to take a standard input,
a 3-digit ordinal date (e.g. 060), and convert it to the cardinal date,
assuming the current year (e.g. 20040229). I also need to be able to
convert parts of that string, the month, to the abbreviation (e.g. 02 to
FEB), and put the parts of that string in different places (e.g. *29*0000 -
*29*2359 *FEB* *2004*). This is for creating daily log reports.


#!/usr/bin/perl

use warnings;
use strict;
use Date::Calc qw/Add_Delta_Days/;

my $current_year = (localtime)[5]+1900;

my $ordinal = 60;
my ($year, $month, $mday) = Add_Delta_Days($current_year, 1, 1, $ordinal-1);

my $month_t = (qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/)[$month-1];

print "$mday $month_t $year\n";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top