Subscribe By RSS or Email

Recent Posts in ‘MySQL’

MySQL – Query by Date Range Using Timestamp

Using MySQL TIMESTAMP, as opposed to DATETIME, only requires a slight modification to our code in order to retreive records that fall within a specific date range (column_name becomes DATE_FORMAT(column_name,’%Y-%m-%d’)). Example usage: Today = ” AND DATE_FORMAT(date_added,’%Y-%m-%d’) = curdate() “ Tomorrow= ” AND DATE_FORMAT(date_added,’%Y-%m-%d’) = date_sub(curdate(),INTERVAL 1 DAY) “ This Week= ” AND year(DATE_FORMAT(date_added,’%Y-%m-%d’))=year(curdate()) “