Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Date conversion script

Reply
Thread Tools

Date conversion script

 
 
Jon Carpenter
Guest
Posts: n/a
 
      04-21-2004
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.


 
Reply With Quote
 
 
 
 
Jack Challen
Guest
Posts: n/a
 
      04-21-2004
Jon Carpenter wrote:
> 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";
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Calling date conversion function before binding the date to a daragrid Sanjeeb ASP .Net Web Controls 2 01-26-2004 06:36 AM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C Programming 3 11-08-2003 09:07 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments