I need your help with two issues I am having:

How do you subtract two dates (both in the format of YYYYMMDD) to obtain the value in days? One date will always be local date and I'm using strftime("%Y%m%d", localtime(time) to obtain it. I do not have nor can I use the Time:Piece or Date:Calc modules at this time. The problem I am having is as long as its the same year (for example 20070108 - 20070101) my code will work fine giving me 7 days. But if I have 20070108 - 20061228 it will return an incorrect amount of days.

My second issue is once I get the amount of days it doesnt appear that I'm able to compare it. I have a variable called $diff_days that returns 7. I then want to compare $diff_days > 15 or $diff_days = 15. Is that possible? What is the best way to handle that because I get a syntax error.

Could you please provide examples since I am very new to Perl.


In reply to Subtracting and Comparing Two Dates by mindful07

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.