Solved

perl date conversion

Posted on 2014-12-15
4
212 Views
Last Modified: 2014-12-20
Hi - I am trying to convert effective date format from 11/20/2014 to 20141120.
I am writing that as a part of my script, and please check the attached script.

When i use the below script and run it seperately it works but when I use it as a part of my script it fails and gives me error message saying "can't use string ("Time::Piece") as an array ref while "Strict refs" in use at c:/Strawberry/perl/lib/Time/Piece.pm line 452, <INFILE> line 5"


use strict;
use warnings;
use Time::Piece;
my $dt = Time::Piece->strptime('01/20/2014', '%m/%d/%Y');
print $dt->strftime('%Y%m%d');
            
let me know what needs to be modified in my script.

Thanks
TESTSCRIPT.txt
0
Comment
Question by:shragi
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40500446
Time::Piece->strftime('$effectiveDate', '%m/%d/%Y');
should be
Time::Piece->strptime($effectiveDate, '%m/%d/%Y');
0
 

Author Comment

by:shragi
ID: 40500491
That did not work, I got the below error when i modified
"error parsing time at C:/strawberry/perl/lib/time/piece.pm line 469, <INLINE> line 5"


my $dt = Time::Piece->strptime('$effectiveDate', '%m/%d/%Y');
print $dt->strftime('%Y%m%d');

also tried             
my $dt = Time::Piece->strptime('$effectiveDate', '%m/%d/%Y');
print $dt->strptime('%Y%m%d');

Thanks
0
 
LVL 84

Expert Comment

by:ozo
ID: 40500496
You did not remove the ' ' around $effectiveDate
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 40500650
As ozo said, you need to remove the single quotes around the $effectiveDate variable.  You are trying to convert the literal string $effectiveDate (which will obviously fail since it is not a date) rather than the value of $effectiveDate.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question