Solved

perl date conversion

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

743 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

12 Experts available now in Live!

Get 1:1 Help Now