I'm using Class::DBI to interface with my MySQL db. Unfortunately, I don't get the fine-grained control of the queries I'm used to. I've had to create a trigger to update a "created_on" column with the current date/time because it's not possible to use MySQL's NOW() function.

Now I need to retrieve all rows that have been added in the past x days. I have used Class::DBI like so to create a new constructor that allows me to search based on date:

Company->add_constructor(get_recent => 'created_on > ?');

Now, I just need to figure out how to pass the new constructor a date in the correct format. I can get a date in the correct format using Time::Piece (which is what I'm using in the trigger to create the column in the first place). However, I need to take this date and subtract x days from it, so I could get all records added in the past 5 days or something. Any help would be greatly appreciated.

I searched CPAN and found tons of date modules, but I'm having a problem finding ones that implement the interval subtraction I need. Date::Calc doesn't seem to have it. I ran a supersearch as well and didn't turn up much.

In reply to Date subtraction (intervals) w/Class::DBI by saberworks

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.