What is the recommended format for storing dates in a database to easily filter out records older than a certain number of days?
Storing dates in a database using the format "YYYY-MM-DD" (e.g. 2022-01-31) is recommended for easy filtering based on date ranges. This format allows for simple comparisons and calculations when querying for records older than a certain number of days.
// Example of filtering records older than 30 days using PHP and MySQL
$days = 30;
$olderThanDate = date('Y-m-d', strtotime("-$days days"));
$query = "SELECT * FROM table_name WHERE date_column < '$olderThanDate'";
// Execute the query and fetch results...