Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How do you remember the number of days in each month?

by chacham (Prior)
on Sep 16, 2014 at 10:04 UTC ( #1100721=poll: print w/replies, xml ) Need Help??

vote on How do you remember the number of days in each month?

By rote learning.
[bar] 15/4%
Via Genetic memory.
[bar] 5/1%
It's provided by my firmware.
[bar] 11/3%
I just remember them.
[bar] 42/11%
Thirty days hath September
[bar] 84/21%
Calendar::Simple
[bar] 9/2%
Knuckle calendar
[bar] 129/33%
My computer gets it right, usually.
[bar] 68/17%
I just ask someone else.
[bar] 16/4%
Someone punches me on the first of the month.
[bar] 16/4%
396 total votes
  • Comment on How do you remember the number of days in each month?
Replies are listed 'Best First'.
Re: How do you remember the number of days in each month?
by salva (Abbot) on Sep 16, 2014 at 15:13 UTC
    I use the iKnuckle app.
Re: How do you remember the number of days in each month?
by LanX (Bishop) on Sep 16, 2014 at 11:29 UTC
    I think every kid in Germany learns the knuckle calendar, I suppose it's pretty widespread in continental Europe or even Eurasia.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      LanX i never seen 'knuckle calendar'in mediterranean area

      L*


      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: How do you remember the number of days in each month?
by blue_cowdawg (Monsignor) on Sep 16, 2014 at 13:29 UTC

    Unix "cal" command is your friend.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; Blog: http://blog.berghold.net Warning: No political correctness allowed.
Re: How do you remember the number of days in each month? (Hrundi V. Bakshi)
by Discipulus (Monsignor) on Sep 16, 2014 at 10:36 UTC
Re: How do you remember the number of days in each month?
by erix (Parson) on Sep 16, 2014 at 15:26 UTC

    I don't have to remember --- postgresql does that:

    select to_char( generate_series( date( cast( to_char(current_date, 'YYYY' ) as integer) || +'-02-01' ) , date( cast( to_char(current_date, 'YYYY' ) as integer) + 1 || +'-01-01' ) , interval '1 month' ) - interval '1 day', 'DD') ; to_char --------- 31 28 31 30 31 30 31 31 30 31 30 31 (12 rows)

    Or, golfed down a bit...

    select to_char(generate_series('20140201','20150101',interval'1mon')-i +nterval'1','DD');

    ...it's shorter than the italian nursery rhyme! ;-)

    update 1, yeah, I'm updating & golfing it a bit, sorry :)

    update 2, (aargh! Oracle wins the Golf contest by 2 characters...

    update 3, (aha! Oracle wins the Golf contest by only 1 character, (pg accepts '1mon' for '1 mon')

    update 4, (aha!)

    select to_char(generate_series('140201','150101',interval'1mon')-inter +val'1','DD'); -- Pg (9.5dev) SELECT TO_CHAR(ADD_MONTHS(DATE'14-1-1',LEVEL)-1,'DD')FROM Dual CONNECT + BY LEVEL<13; -- Oracle (10g) SELECT TO_CHAR(TO_DATE(LEVEL,'MM')-1,'DD')FROM Dual CONNECT BY LEVEL<1 +3; select to_char(to_date(generate_series(2,13)::text,'MM')+interval'1y - +1s','DD'); -- Pg. awful but works :) SELECT TO_CHAR(LAST_DAY(TO_DATE(LEVEL,'MM')),'DD')FROM Dual CONNECT BY + LEVEL<13; -- Oracle. "saved 3 char' SELECT TO_CHAR(TO_DATE(LEVEL,'MM')-1,'DD')FROM Dual CONNECT BY LEVEL<1 +3; -- Oracle. "start from december" (shortest) select 30+(3+(3*m+3)%5-(3*m+1)%5)/5from generate_series(3,13)f(m); -- + wrog's (short but incomplete: march through january)

    Looks like Oracle wins this little golfing contest. Ah well... it has to have something to justify the price ;-))

    Well played chacham++ :-)

      About the same in Oracle

      SQL> SELECT 2 LEVEL Month, 3 TO_CHAR(LAST_DAY(TO_DATE(LEVEL || '/1/' || 4 TO_CHAR(SYSDATE, 'YYYY'), 'MM/DD/YYYY')),'DD') Days 5 FROM 6 Dual 7 CONNECT BY 8 LEVEL <= 12; MONTH DA ---------- -- 1 31 2 28 3 31 4 30 5 31 6 30 7 31 8 31 9 30 10 31 11 30 12 31 12 rows selected.

      After the update in the parent, i realized this too could be shortened:

      SELECT TO_CHAR(ADD_MONTHS(TO_DATE('1', 'DDD'), LEVEL) - 1, 'DD') FROM Dual CONNECT BY LEVEL < 13;
      But, if we can cheat and specify the year, using the ANSI date literal is slightly shorter:
      SELECT TO_CHAR(ADD_MONTHS(DATE '2014-1-1', LEVEL) - 1, 'DD') FROM Dual CONNECT BY LEVEL < 13;

      In a race with the parent to find the shortest SQL. :) So far we went with a literal data (which locks it to 2014), but he outdid me by removing the '20' from the date. Touché!

      Though, not to be outdone, we'll find something shorter (as of update 4) and even go back to working for every year:

      SELECT TO_CHAR(LAST_DAY(TO_DATE(LEVEL,'MM')),'DD')FROM Dual CONNECT BY + LEVEL<13;

      Saved 3 characters. :)

      If we can start from December, we'll save 8 more characters (for a total of 11):

      SELECT TO_CHAR(TO_DATE(LEVEL,'MM')-1,'DD')FROM Dual CONNECT BY LEVEL<13;
Re: How do you remember the number of days in each month?
by SuicideJunkie (Vicar) on Sep 16, 2014 at 14:32 UTC

    I don't bother trying to remember or calculate. Months are quite meaningless anyways.

    What *is* important is how many days are left until the weekend!

      Unless you get paid on the first day of each month - then it matters.

        If you don't spend it all, then the exact time of more money coming in won't matter.

        Just check in every now and then to dump the excess into RRSPs and stuff.

Re: How do you remember the number of days in each month?
by wrog (Friar) on Sep 18, 2014 at 00:36 UTC
    30+(3+ (3*$_+3)%5 - (3*$_+1)%5)/5

    works for March (3) through January (13).

    Or to put it another way, you add 1 to the month and then multiply by 3 and if subtracting 2 from that crosses through a mod-5 boundary then you have a 30 day month, otherwise you have a 31 day month

    So May (6*3=18 —→ 16) has 31, while June (21 —→ 19) has 30.

    Yeah, that's how I remember this.

      TIMTOWTDI! =)

      DB<105> print 30+($_+($_>7))%2 for 1..12 31 30 31 30 31 30 31 31 30 31 30 31 DB<106> print 30+($_+($_>7))%2-2*($_==2) for 1..12 31 28 31 30 31 30 31 31 30 31 30 31 DB<113> print ((30,31,28)[($_+($_>7))%2-($_==2)]) for 1..12 31 28 31 30 31 30 31 31 30 31 30 31 30 31

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

      Interesting.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: How do you remember the number of days in each month?
by chacham (Prior) on Sep 16, 2014 at 13:46 UTC

    Someone punches me on the first of the month.

    And how exactly does that help you remember how many days are in the month?

      You read the number off the large digital display on the wall labelled "NUMBER OF DAYS SINCE LAST PUNCHED". Then reset it to zero, or else you'll be off next month.

      1 Peter 4:10
Re: How do you remember the number of days in each month?
by barrd (Abbot) on Sep 17, 2014 at 06:58 UTC
    Mnemonic devices save me :) So it's 30 days hath September...

    Same for (UK?) lines of the treble clef, was taught this in primary school;
    Every Good Boy Deserves Females

      Where did you go to school? :)

      The mnemonic according to wikipedia is: Every Good Boy Deserves Favour or Every Good Boy Deserves Fudge

        You don't even want to know how we were taught the order of the resistor band colors.

        Heh - I went to Primary school in Scotland during the 70's, before the days of crazy political correctness, teachers could still have some fun. ;)

        Chicago area during the 70s we learned Every Good Boy Does Fine.

        Funny how these things often take on a life of their own at some point.

Re: How do you remember the number of days in each month?
by ambrus (Abbot) on Sep 23, 2014 at 10:51 UTC

    I remember if I must from knowing that the month of my birthday and the month following it both have 31 days, but usually I try to leave such error-prone computations to computers instead. If you are using perl, I generally recommend the Date::Manip module, unless you need sub-second precision.

Re: How do you remember the number of days in each month?
by Bloodnok (Vicar) on Sep 22, 2014 at 14:18 UTC
    Methinx that there really ought to be an 'Other' option - there must be others out there that are followers of Kevin Bloody Wilsons' DILLGAFF - there's only one month I could be considered to care about and as my birthday's toward the beginning of it, I don't care how long it is since after that, I am, if I'm really lucky, but one year older ... and that, at the moment, seems to be happening every year...

    A user level that continues to overstate my experience :-))
Re: How do you remember the number of days in each month?
by chacham (Prior) on Sep 16, 2014 at 13:40 UTC

    It's kinda neat and allotta fun to write small scripts in whatever language you're currently using. Not that they are always useful though. :)

View List Of Past Polls


Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2018-01-21 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (227 votes). Check out past polls.

    Notices?