in reply to Re^2: Detecting 1 day ago
in thread Detecting 1 day ago

No, you don't. You want a MySQLish way of doing it because you're using MySQL and it'll be 10x faster to have MySQL figure it out.

Otherwise, look up DateTime, Date::Calc, or Date::Manip. All three have functionality to do what you're looking for.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^4: Detecting 1 day ago
by Anonymous Monk on Feb 25, 2006 at 04:33 UTC
    Okay, the MySQL way would be something like the following?
    SELECT * FROM messages -> WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= message_data;
    I generally do this in a three stage format, so if the above is true, I know there's a better way of doing this.
    my $data = qq(SELECT * FROM messages..); my $sth = $dbh->prepare($data); $sth->execute();
    Instead of caring what results came back, I only need to check to see that at least SOMETHING came back in the last day. How would I do that without having to do an sth->fetch?

    Sorry, new to mysql.

      my $sth = $dbh->prepare( q{SELECT 1 FROM messages WHERE DATE_SUB(CURDA +TE(),INTERVAL 1 DAY) <= message_data LIMIT 1; } ); $sth->execute(); print "We got it" if $sth->rows();
      See exists clause if mysql supports it, and if you can make it better fits your needs..


      Evan Carroll
      www.EvanCarroll.com
        Hi.

        Okay, I tried your code and it doesn't error out (which is great!) though I'm not sure what the problem is. It matches something every time. I then changed it down to 1 MINUTE instead of 1 DAY and it still matches every time when the last entry was some hours ago.