Solved

perl date conversion

Posted on 2014-12-15
4
209 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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now