Date calculations : yes there are modules for this on CPAN, but wouldn't you like to know how to do this kind of stuff :)

Some algorithms useful for calculating:

#!/usr/bin/perl -w #=========== declare includes ============= use strict; use diagnostics-verbose; #========== declare variables ============= my($Adjuster,$GregorianDay,$JulianDay,$LastOfMonth,$day,$month,$year); my(@DaysOfWeek); # Need to print out calendar for a given year? # 30 days hath September, April, June and November # all the rest have 31 # except February 28 days clear, 29 each leap year # the rule for working out leap years = # If the year is divisible by 100 it's NOT a leap year # If the year is divisible by 4 or 400 it's a leap year $LastOfMonth = '30'if ($month == (4||6||9||11)); $LastOfMonth = '31'if ($month == (1||4||5||7||8||10||12) ); if ($month == 2){ if ( $year % 100 != 0 && $year % 4 == 0 || $year % 400 == 0 ){ $LastOfMonth = '29'; } else { $LastOfMonth = '28'; } } # The programmatic way to convert the date into the name for the day o +f the date given # this script expects to be fed the date, which it will then output a +number # which represents Julian day and Gregorian day with Sunday=0 # Julian days are useful for calculating dates before the change to th +e Gregorian Calendar $day= 1; $month=3; $year=2003; $Adjuster = int ( ( 14-$month )/12 ); $month = int ( $month +( ( $Adjuster*12 )-2 ) ); $year = int ( ( $year -$Adjuster ) ); $JulianDay = (5+$day+$year+int($year/4)+int(31*$month/12) ) %7; $GregorianDay = ($day + $year + int($year/4) - int($year/100) + int($y +ear/400) +int (31*$month/12) ) %7; print "The value of \$JulianDay is: ",$JulianDay,"\n"; print "The value of \$GregorianDay is: ",$GregorianDay,"\n"; # use the value output on an array like this to get the day of the wee +k @DaysOfWeek=qw( Sunday Monday Tuesday Wednesday Thursday Friday Saturday );

In reply to Useful Date Algorithms by Sol-Invictus

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.