MYSQL常用日期操作
mysql查询今天、昨天、7天、近30天、本月、上一月 数据 今天
select * from 表名 where to_days(时间字段名) = to_days(now());
昨天
SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 时间字段名) <= 1
7天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名)
近30天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名)
本月
SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
上一月
SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( 时间字段名, '%Y%m' ) ) =1
#查询本季度数据
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(now());
#查询上季度数据
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));
#查询本年数据
select * from `ht_invoice_information` where YEAR(create_date)=YEAR(NOW());
#查询上年数据
select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));
查询当前这周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());
查询上周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;
查询当前月份的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')
查询距离当前现在6个月的数据
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
查询上个月的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')
select * from ` user ` where DATE_FORMAT(pudate, ' %Y%m ' ) = DATE_FORMAT(CURDATE(), ' %Y%m ' ) ;
select * from user where WEEKOFYEAR(FROM_UNIXTIME(pudate,'%y-%m-%d')) = WEEKOFYEAR(now())
select *
from user
where MONTH (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = MONTH (now())
select *
from [ user ]
where YEAR (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = YEAR (now())
and MONTH (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = MONTH (now())
select *
from [ user ]
where pudate between 上月最后一天
and 下月第一天
select * from user where pudate between unix_timestamp(date_sub(curdate(),interval (day(now())+1) day)) and unix_timestamp(date_sub(date_sub(curdate(),interval -1 month ),interval (day(now())-2) day));
select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now())
SELECT date( c_instime ) ,curdate( )
FROM `t_score`
WHERE 1
LIMIT 0 , 30
MYSQL常用日期操作的更多相关文章
- MySQL常用权限操作
MySQL常用权限操作 ** ubuntu mysql 8.0.21修改root密码 ** 1.查看默认安装密码: sudo cat /etc/mysql/debian.cnf 2. 登录mysql ...
- MySql常用日期函数(转载)
/*date_add(date,interval expr type)和date_sub(date,interval expr type)执行日期运算. date 是一个 datetime 或date ...
- Mysql常用表操作 | 单表查询
160905 常用表操作 1. mysql -u root -p 回车 输入密码 2. 显示数据库列表 show databases 3. 进入某数据库 use database data ...
- Java常用日期操作
对java中常用的日期操作进行整理. 1.日期格式化 /* * 日期格式化类(必须掌握) * API: * G Era 标志符 Text AD y 年 Year 1996; 96 M 年中的月份 Mo ...
- mysql中日期操作
1 获取当前时间 now() select now(); +---------------------+ | now() | +---------------------+ | -- :: | +-- ...
- mysql常用的操作
数据库的常用操作:create database db1; #创建数据库show databases; #查看所有数据库show create database db1;#查看创建的指定数据库alte ...
- MySQL常用日期时间函数
日期和时间函数: MySQL服务器中的三种时区设置: ①系统时区---保存在系统变量system_time_zone ②服务器时区---保存在全局系统变量global.time_zone ③每个客户端 ...
- mysql常用语法操作
一.用户管理: 1.新建用户: >CREATE USER name IDENTIFIED BY 'ssapdrow'; 2.更改密码: >SET PASSWORD FOR name=PAS ...
- MySql常用数据操作
1.数据库操作: MySQL服务管理命令: 1.启动服务:sudo service mysql start 2.停止服务:sudo service mysql stop 3.重新启动服务:sudo s ...
随机推荐
- HDOJ5877(dfs序+离散化+树状数组)
Weak Pair Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- RHEL6 64位ASM方式安装oracle 11gR2(一)
本文转载自 http://vnimos.blog.51cto.com/2014866/1221361 一.安装前的准备 1.1 确定操作系统环境 1 2 3 4 5 6 7 8 9 10 11 12 ...
- thinkphp中配置信息的二维数组设置与使用
有时候配置信息是二维数组 1.配置 <?php return array ( // 阿里大鱼短信配置 'dayu_appkey'=>'xxx', 'dayu_secretKey'=> ...
- MFC学习(三)程序入口和执行流程
1) WIN32 API程序当中,程序入口为WinMain函数,在这个函数当中我们完成注册窗口类,创建窗口,进入消息循环,最后由操作系统根据发送到程序窗口的消息调用程序窗口函数.而在MFC程序当中我们 ...
- Unity3D 4.3在Windows下打包iOS资源
想当年,想弄iOS的版本必须弄台mac机器,虽然一开始要弄iOS的时候觉得在mac上开发感觉挺高富帅的,但是做多了之后就觉得在mac上开发各种不方便.现在好了,Unity3D 4.3开始支持在Wind ...
- python's twenty-sixth day for me 模块
configparser 模块: 该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键 = 值). 创建文件: # 创建文件 i ...
- PHP安装使用Zend Opcache扩展
简介 Zend OPCache 的前身是Zend Optimizer + (Zend O+),于 2013年3月中旬改名为 Opcache.其通过 opcode 缓存和优化提供更快的 PHP 执行过程 ...
- cs231n神经网络 常用激活函数
CS231n课程笔记翻译:神经网络笔记1(上) 一.常用激活函数 每个激活函数(或非线性函数)的输入都是一个数字,然后对其进行某种固定的数学操作.下面是在实践中可能遇到的几种激活函数: ——————— ...
- sendMail在centos下的安装
一.sendEmail介绍 SendEmail is a lightweight, command line SMTP email client. If you have the need to ...
- java中的类型安全问题-Type safety: Unchecked cast from Object to ...
首先,java语言室类型安全的,通常我们遇到这个问题是出现在Object转化为目标类型时, 这个转化并不是安全的.这个问题普遍认为因为使用了jdk1.5或者1.6的泛型, request.getAtt ...