Liam Liam - 1 year ago 95
Perl Question

Perl, issue converting time stamp to readable date

I have the following one liner, this should convert the date from one week ago today to a readable format.

my $week_ago = strftime("%Y-%m-%d", time - 604800);

However I get the following error:

Usage: POSIX::strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)

Can anyone suggest what the issue is here? From my understanding,
should convert a time stamp to a readable date.

Answer Source

As your error message says, POSIX's strftime takes a list of vaules, not a unix timestamp. You need to call localtime or gmtime before you call it.

 my $week_ago = strftime("%Y-%m-%d", localtime(time - 604800)); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download