0
Thanks

A few words of thanks would be greatly appreciated.

MySQL - SELECT ... YESTERDAY

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)
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
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.

Published by . Latest update on by Virginia Parsons.

This document, titled "MySQL - SELECT ... YESTERDAY," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

1 Comment