P is for Practical PerlMonks

### comment on

 Need Help??
Hello. For what it's worth, I wrote the following to be able to determine whether date1 is within 3 days of date2 etc. I didn't know about Date::Manip.
```sub abs_day
{
# this subroutine accepts a month, day, and two-digit year in
# mm/dd/yy numerical form, e.g., 3/23/04.
# it then calculates the "absolute day",
# i.e., the number of days
# since day 0, which is the turn of the 21st century.
# so, 1/10/2000 is absolute day 10;
# 1/10/2001 is absolute day 376
# (because year 2000 was a leap year).

# the routine deals with leap years by
# multiplying years by 365.25, and then rounding down.

my \$month = shift(@_);
my \$day = shift(@_);
my \$year = shift(@_);

if (\$debug)
{
print "i'm in abs_day and month is \$month,",
" day is \$day, year is \$year\n";
}
my \$abs_day;
undef(\$abs_day);

# so each year has 365.25 days
# years are of the form 00, 01, 02, etc.
\$abs_day = \$year * 365.25;
# add .75 to account for fact that year 00 is a leap year
\$abs_day = \$abs_day + .75;

if (\$debug)
{
print "abs_day is \$abs_day after adding .75 to yr*365\n";
}

if (\$month == 1) #jan
{
\$abs_day =  \$abs_day + 0;
}
if (\$month == 2) #feb
{
\$abs_day = \$abs_day + 31;
}
# starting in march, we add .25 to number of days
# to account for leap year
if (\$month == 3) #mar
{
\$abs_day = \$abs_day + 59.25;
}

if (\$month == 4) #apr
{
\$abs_day = \$abs_day + 90.25;
}
if (\$month == 5) #may
{
\$abs_day = \$abs_day + 120.25;
}
if (\$month == 6) #jun
{
\$abs_day = \$abs_day + 151.25;
}
if (\$month == 7) #jul
{
\$abs_day = \$abs_day + 181.25;
}
if (\$month == 8) #aug
{
\$abs_day = \$abs_day + 212.25;
}
if (\$month == 9) #sep
{
}
if (\$month == 11) #nov
{
\$abs_day = \$abs_day + 304.25;
}
if (\$month == 12) #dec
{
\$abs_day = \$abs_day + 334.25;
}

\$abs_day = \$abs_day + \$day;
if (\$debug)
{
print "now that we have added year, month, and",
" day, abs_day is \$abs_day\n";
}

\$abs_day = sprintf "%d", \$abs_day;
if (\$debug)
{
print "now that we have converted from float to integer,",
" abs_day is \$abs_day\n";
}

return \$abs_day;
}

In reply to Re: How do I Compare Dates by Anonymous Monk
in thread How do I Compare Dates 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":

• Are you posting in the right place? Check out Where do I post X? to know for sure.
• Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
• Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
• Want more info? How to link or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2023-12-09 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What's your preferred 'use VERSION' for new CPAN modules in 2023?

Results (37 votes). Check out past polls.

Notices?