Date conversion script

Discussion in 'Perl' started by Jon Carpenter, Apr 21, 2004.

  1. 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.
     
    Jon Carpenter, Apr 21, 2004
    #1
    1. Advertising

  2. Jon Carpenter

    Jack Challen Guest

    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";
     
    Jack Challen, Apr 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    653
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,380
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    575
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    757
    Richard Heathfield
    Nov 8, 2003
  5. Sanjeeb
    Replies:
    2
    Views:
    203
Loading...

Share This Page