MySQL/日期:修订间差异
来自康健生活
| 第124行: | 第124行: | ||
| class="td-pre-noborder" style="padding:0;" | <syntaxhighlight lang="mysql">SELECT DAYOFMONTH( NOW( ) );</syntaxhighlight> || 19 || | | class="td-pre-noborder" style="padding:0;" | <syntaxhighlight lang="mysql">SELECT DAYOFMONTH( NOW( ) );</syntaxhighlight> || 19 || | ||
|- | |- | ||
| | | 查询今天的数据 | ||
| class="td-pre-noborder" style="padding:0;" | <syntaxhighlight lang="mysql"></syntaxhighlight> || || | | class="td-pre-noborder" style="padding:0;" | <syntaxhighlight lang="mysql">SELECT * FROM 表名 WHERE to_days(时间字段名) = to_days(now());</syntaxhighlight> || || | ||
|- | |- | ||
| | | 查询昨天的数据 | ||
| class="td-pre-noborder" style="padding:0;" | <syntaxhighlight lang="mysql"></syntaxhighlight> || || | | class="td-pre-noborder" style="padding:0;" | <syntaxhighlight lang="mysql">SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 时间字段名) <= 1</syntaxhighlight> || || | ||
|- | |- | ||
| | | 查询近 7 天的数据 | ||
| class="td-pre-noborder" style="padding:0;" | <syntaxhighlight lang="mysql"></syntaxhighlight> || || | | class="td-pre-noborder" style="padding:0;" | <syntaxhighlight lang="mysql">SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名)</syntaxhighlight> || || | ||
|- | |- | ||
| | | | ||