MySQL - SELECT ... YESTERDAY

Ask a question
MySQL provides easy access to database records and makes it possible to carry out manipulations on the data. To select time-related data from the database, MySQL provides a simple keyword known as INTERVAL. The INTERVAL MySQL command allows the data to be compared within the time specified in the parameter and selects only those records that match the selection criteria. To select database records which are one day old for example, the parameter in the INTERVAL MySQL command should be 1. For previous records, the number of days can be specified according to the parameter.
  • Use the following syntax:
    • SELECT * FROM myTable WHERE field_date = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 1 DAY)
  • In order to select previous records:
    • SELECT * FROM myTable WHERE field_date = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 2 DAY)
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team