MySQL Concatenate and Compare

Ever come across a database table where the date and time where two separate fields? How do you run comparisons against them? What if you need to get all records between Monday at 5pm and Tuesday at 2:30am?

You have to concatenate the fields before doing comparisons. In MySQL I found that this is extremely easy:

SQL:
  1. SELECT * FROM `table` WHERE CONCAT(`date`,' ',`time`) BETWEEN2006-10-02 17:00:00AND2006-10-03 02:30:00

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • Reddit
  • Furl
  • NewsVine
  • Simpy
  • Slashdot
  • Spurl
  • StumbleUpon
  • YahooMyWeb
  • TailRank

Home | MySQL | MySQL Concatenate and Compare