Liam Liam - 3 months ago 10x
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.


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));