Not quite sure what you mean by 'odd' and 'even'.

January 7 2006 is the 13,155th day since the start of the epoch. It is therefore 'odd' by your calculation (update: I should have written something like "by your calculation adjusted as per replies above"). However, January 7 2007 will be the 13,520th day, and therefore 'even'.

If that is what you want, fine, just ignore this post.

However, for a more normal definition of 'odd/even' - ie Jan 7 is odd, Jan 8 is even, Feb 1 is odd, Feb 2 is even, etc - you could do:

print +( localtime )[3] % 2 ? "odd\n" : "even\n";

Or else, counting from the beginning of the year - ie March 1 is the 60th day (even) in a normal year, but the 61st day (odd) in a leap year:

print +( localtime )[7] % 2 ? "even\n" : "odd\n";

In reply to Re: odd or even day? by Not_a_Number
in thread odd or even day? by jondkent

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.