mysqltimestamp

MySQL timestamp select date range


I have a UNIX timestamp column in MySQL and I want to select a date range for example, all timestamps which are in Oct 2010.


Solution

  • Usually it would be this:

    SELECT * 
      FROM yourtable
     WHERE yourtimetimefield>='2010-10-01'
       AND yourtimetimefield< '2010-11-01'
    

    But because you have a unix timestamps, you'll need something like this:

    SELECT * 
      FROM yourtable
     WHERE yourtimetimefield>=unix_timestamp('2010-10-01')
       AND yourtimetimefield< unix_timestamp('2010-11-01')