in reply to Re: Date question
in thread Date question

I must be doing something wrong. I have use HTTP::Date; in there and I call it like this:

$date2 = parse_date($date);

but this gets returned:

"Undefined subroutine &main::parse_date called at line 986"

Replies are listed 'Best First'.
Re^3: Date question
by almut (Canon) on Oct 30, 2008 at 22:02 UTC

    parse_date() is not exported by default, so you can either write

    $date2 = HTTP::Date::parse_date($date);

    or import the function into your namespace

    use HTTP::Date qw(parse_date);

    (See Exporter for what this is about)

      Thanks for the help. That worked, sort of. Here's the deal. I have a date formatted in a field like this:

      2008-10-30

      But when my script pulls it out for the RSS feed, the feed count is as a day ealier even though, if I look at the source of the feed it's correct. So a story published today has a pubDate of 2008-10-30 (and it's correct in the source), but viewing the feed it says the date is 2008-10-29. So I thought that by changing it to the GMT format my problem would be fixed. It's not.

      When I run this parser it just turns 2008-10-30 into:

      2008-10-30 00:00:00

      Any ideas?

        You could use the str2time() / time2str() functions instead (which are exported by default, btw).

        my $date = "2008-10-29"; my $http_date = time2str( str2time($date) ); # Tue, 28 Oct 2008 23:0 +0:00 GMT

        You can also explicitly specify the time zone with str2time(), e.g.

        str2time("2008-10-29", "GMT") # --> Wed, 29 Oct 2008 00:00:00 GMT str2time("2008-10-29", "-0800") # --> Wed, 29 Oct 2008 08:00:00 GMT str2time("2008-10-29", "+0100") # --> Tue, 28 Oct 2008 23:00:00 GMT

        (As to your off-by-one day problem, I'm not really sure I understand what you mean, so I can't comment on that...)