FYI, I can't replicate the problem. I always get 6 days apart, even with 11/1/2008 (and even when pretending to be in another time zone, e.g. via TZ=PST).  Not really sure if it might have to do with the timezone, but maybe you could just try by switching to timegm()/gmtime() (and $ENV{TZ}="GMT", as strftime is TZ-aware).  Or maybe your system's POSIX library (strftime) is just broken...

Update: actually, I can reproduce the issue when using a time zone for which my system does handle daylight savings time1 (plus using a different start date, as in (most parts of) Europe the DST switch is done on the last Sunday in October — as opposed to the first Sunday in November).  Similarly, using TZ=GMT 'fixes' the issue:

$ TZ=CET ./727202.pl -s 10/25/2008 The start day is 10/25/2008 and the end day is 10/30/2008 23:00 $ TZ=GMT ./727202.pl -s 10/25/2008 The start day is 10/25/2008 and the end day is 10/31/2008 00:00

(to show the hour, I changed the end_day format to "%m/%d/%Y %H:%M")

Anyhow, as others have said, it's probably better to use a module that has already solved this, and other date/time issues...

___

1 For reasons I haven't investigated further, it isn't sufficient to set my TZ to a time zone in the US — when doing so, I do get the respective local time, but without the local daylight savings time being handled correctly... (which is why I initially couldn't replicate the problem)


In reply to Re: date string conundrum by almut
in thread date string conundrum by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.