in reply to Re^3: Date question
in thread Date question

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?

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

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