Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATE::MANIP

Status
Not open for further replies.

hello99hello

Programmer
Jul 29, 2004
50
CA
Could anyone help with the date manip function:

Basically, I am trying to change Date from MM/DD/YYYY(05/01/2003)TO 01-May-2003

use Date::Manip;

my $input_date ;
my $ouput_date ;
my $datestr ;
my $date ;


$input_date = "02/03/2003" ;
#use Date::Manip qw(ParseDate $input_date);
$datestr = ParseDate($input_date);
print "Date::Manip gives: $datestr\n";

However, it is giving massive errors

Thanx for your help
 
The errors would be nice ...

We don't mind helping, but I'm not setting up a test rig for every query that comes through here

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Sorry Paul,

Bear with me here, I am new at programming.

I found that there current version of Date::Manip has to be reinstall. The sys admin has promised to reinstall.

Meanwhile, I am willing to pay if you could help with the script to change Date from MM/DD/YYYY(05/01/2003)TO 01-May-2003.

Again sorry and I promise I would not bother u again.

Regards,
Tayo
 
You probably shouldnt use date::manip cause its huge... and for just formatting why not make a hash of months... or find one of the smaller date modules.

but somehting like:

my $date = ParseDate("28-02-2002");
print UnixDate($date, "%E-%B-%Y");

should be close...
 
Hello All,

I am running this simple program for the the following and I am still getting the error below, Though the output file to be fine. I am running this simple program for the the following and I am still getting the error below, Though the output file seems to be fine. Please help on why I am still getting error:

sample input_file:
200069,3/5/1990,3/5/1990,11/9/1990,3/5/1990

sample output_file:
200069, 5-Mar-1990, 5-Mar-1990, 9-Nov-1990, 5-Mar-1990


Program:
#!/usr/bin/perl

use strict ;
use warnings ;
use Date::Manip ;

my ($input_file ) ;
my ($input_record) ;
my ($output_file);
my ($array_record);
my (@array) ;
my ($array) ;
my (@array_file);
my ($new_record);
my ($input_date) ;
my ($date) ;

$input_file = "emp_in.txt";
$output_file = "emp_out.txt";

#check input file
(-e $input_file) || die ("input file does not exist \n") ;
open(INPUT, "$input_file") || die ("could not open infile\n");
open(OUTPUT, ">$output_file") || die ("could not open outfile \n") ;
@array_file = <INPUT> ;
foreach $array_record (@array_file){
@array = split (",", $array_record) ;

#Start Change Here
chomp($array[1]);
$date = ParseDate("$array[1]") ;
$array[1] = UnixDate($date, "%e-%b-%Y\n") ;
chomp($array[1]);

chomp($array[2]);
$date = ParseDate("$array[2]") ;
$array[2] = UnixDate($date, "%e-%b-%Y\n") ;
chomp($array[2]);

chomp($array[3]);
$date = ParseDate("$array[3]") ;
$array[3] = UnixDate($date, "%e-%b-%Y\n") ;
chomp($array[3]);#LINE43

chomp($array[4]);
$date = ParseDate("$array[4]") ;
$array[4] = UnixDate($date, "%e-%b-%Y\n") ;
chomp($array[4]);
#Stop Change Here

$new_record = join ',', @array; $LINE51
print OUTPUT "$new_record\n";

}
close (INPUT) ;
close (OUTPUT) ;

ERROR:
Use of uninitialized value in scalar chomp at ./emp.pl line 43, <INPUT> line 360.
Use of uninitialized value in join or string at ./emp.pl line 51, <INPUT> line 360.
 
Code:
use warnings ;
is why you are getting these warnings not errors.

could be you've got a blank line in your input file, or there's an assignment before theres a value. If you're happy with your results just take out the line above.

TIP: If you use the [ code][/ code] (ignore spaces) tags, to preserve indentation I'll have another look for the actual line causing the problem, without indentation, I'm too busy washing my hair ;-)

Regards
HTH
--Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
#!/usr/bin/perl ### this is unix

so if you are not an obstinate perl fanatic
and accept to use the properly tool for this job...

in your exemple, you make string substitions,
no computing, no conditional stats, so why use perl?[/b]

you could call the easy, old, fantastic sed.

ASSUMED the input look like (you said):

200069,3/5/1990,3/5/1990,11/9/1990,3/5/1990

and the output should be:

200069, 5-Mar-1990, 5-Mar-1990, 9-Nov-1990, 5-Mar-1990

few line sed does it!
Code:
s/\//-/g
s/\<[1-9]-/0&/g
s/,01-\(..\)/, \1-Jan/g
s/,02-\(..\)/, \1-Feb/g
s/,03-\(..\)/, \1-Mar/g
s/,04-\(..\)/, \1-Apr/g
s/,05-\(..\)/, \1-May/g
s/,06-\(..\)/, \1-Jun/g
s/,07-\(..\)/, \1-Jul/g
s/,08-\(..\)/, \1-Aug/g
s/,09-\(..\)/, \1-Sep/g
s/,10-\(..\)/, \1-Oct/g
s/,11-\(..\)/, \1-Nov/g
s/,12-\(..\)/, \1-Dec/g
1 line: change / to -
2 line: translate 1-1-1999 to 01-01-1999
and 11-11-1999 to 11-11-1999 :)
other lines, inverse the order and write month name
according to 1.st id after a ','
NOTA: the comma ',' and the slash '/' are really important.
the case: 0/0/1999 is NOT yet implemented!
 
And if you keep wanting to use perl then also put the code in a loop... You had the idea with the first foreach, just do it again for the @array to change all the dates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top