$daysfrom = ($yyyy % 4 ? 365 : 366) isn't sufficient for leap years .. there's another part of the rule -- e.g. Feb 1900 only had 28 days but Feb 2000 had 29.
google results
I see you were trying to avoid other modules, but just for an example (and cause it's a module i use alot), here's a partial
Date::Calc solution:
my $birthday = '2000-01-02'; # yyyy-mm-dd
use Date::Calc qw/Delta_Days Today Add_Delta_YMD/;
my @date = split /-/, $birthday;
$date[0] = (Today())[0]; # set the year to current year
print Delta_Days( Add_Delta_YMD(@date,-1,0,0), @date ); # days since
+last one
print Delta_Days( @date, Add_Delta_YMD(@date,1,0,0) ); # days until
+next one
Update: added in the Add_Delta_YMD to account for birthdays on 2/29
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.