PDA

View Full Version : Resolved another date problem :(


bazz
10-25-2008, 08:10 PM
Hi,
resolved it with Date:Calc qw(:all);
I am converting a date (20081012) to October 2008. Well I have tried.


my $timestamp = build_timestamp ($fileStartDate);
my $date_to_output = date_conversion($timestamp);


sub date_conversion {
use Date::Parse;
my $timestamp = shift;

#strftime uses "%a %b %d %H:%M:%S %Z %Y".
my $finished_date = strftime("%a %Z %Y",$timestamp);
return $finished_date;
}


# build a unix timestamp
sub build_timestamp {
my $iso_date = shift;
# parse and convert date to unix time
my $timestamp = str2time($iso_date);
my $newtimestamp = ($timestamp/86400);
return $newtimestamp;
}


Unfortunately, I get this error and I don't understand it.


Usage: POSIX::strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) at mainpage line 446, <DAT> line 21


Please give me a nudge.

bazz

FishMonger
10-25-2008, 08:19 PM
strftime is expecting a 9 element list as is returned by localtime()

Try:my $finished_date = strftime("%a %Z %Y", localtime($timestamp) );

KevinADC
10-25-2008, 10:16 PM
Loading up Date::Calc for just that seems like overkill. But if you have other uses for Date::Calc its a good single interface to your date calculation requirements.

bazz
10-25-2008, 11:21 PM
Thank you both.

I do have other needs for date calc and it works now. But I shall try to get Fishmonger's idea to work for me anyway.

bazz

KevinADC
10-25-2008, 11:40 PM
You would have to convert your 20081012 date to epoch time to use it as Fish shows. You can do that with Time::Local but I see no need to do that if you are using Date::Calc.

bazz
10-25-2008, 11:44 PM
Thanks Kevin, I'll try to remember that :)

bazz