1752782 Members
6552 Online
108789 Solutions
New Discussion юеВ

Perl scripting

 
SOLVED
Go to solution
Shannon Petry
Honored Contributor

Perl scripting

I was wondering if there is an easy way to grap the date in certain formats within a perl script.
Using "time" I can get the long date, and parse only what I need but I would figure their is an easy way to get
YYYYMMDDhhmm
or
YYYYMMDD-hhmm
I can do this with
/usr/bin/date +%Y%m%d-%H%M

Thanks in advance for Ideas

Shannon
Microsoft. When do you want a virus today?
3 REPLIES 3
John Bolene
Honored Contributor
Solution

Re: Perl scripting

try this
use Time::Local;
$TIME = timelocal($sec, $min, $hours, $mday, $mon, $year);

you can then use these values in any way you want
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com
Shannon Petry
Honored Contributor

Re: Perl scripting

Thanks, I had some docs regarding your command, but the docs did not show to include a time mod....

Thans for the help!
Microsoft. When do you want a virus today?
Frederic Soriano
Honored Contributor

Re: Perl scripting

Hi Shannon,

You could also use the POSIX::strftime function to display a date in a special format, as in [have a look at man page strftime(3C)]:

--snip--
printf STDOUT "Date is %s.\n", POSIX::strftime('%y/%m/%d', localtime(time))
--snip--

John's suggestion is better to manipulate each item differently.

Best regards.

Fred.