MySQL: finding number of days different

Posted on Friday, August 21st, 2009    •    1 Comment    •    460 views
WP Greet Box icon
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.

While working on an invoice system, I want to project a list of invoices that are overdue for certain amount of days, or a list of invoices that are going to be due in certain amount of days. Instead of implementing the filtering in PHP code, I am thinking to let MySQL query performs the filtering.

The datediff seems is not my solution, it just doesn’t work out for my MySQL. Hence I come across with this solution from this source http://mysql-tips.blogspot.com/2005/04/mysql-difference-between-dates-in.html. It is pretty simple and clean.

SELECT * FROM invoices WHERE (TO_DAYS(now())-TO_DAYS(inv_duedate)) > 0
Share and Enjoy:
  • Digg
  • StumbleUpon
  • Technorati
  • del.icio.us
  • Facebook
  • Twitter
  • Reddit
  • MySpace
  • Google Bookmarks
  • MisterWong
  • Ping.fm
  • Slashdot
  • RSS
  • Live
  • LinkedIn
  • email

1 Response to “MySQL: finding number of days different”

Leave a Reply