MySQL Concatenate and Compare

Like this blog? Consider exploring one of our sponsored banner ads...

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:

SELECT * FROM `table` where CONCAT(`date`,' ',`time`) between2006-10-02 17:00:00AND2006-10-03 02:30:00

About this entry