MySQL的YEARWEEK函数(转)
2024-10-03 06:56:11
- MySQL的YEARWEEK函数以及查询本周数据
-
MySQL的YEARWEEK函数以及查询本周数据MySQL 的 YEARWEEK 是获取年份和周数的一个函数,函数形式为 YEARWEEK(date[,mode])
例如 2010-3-14 ,礼拜天 www.2cto.com SELECT YEARWEEK('2010-3-14') 返回 11 SELECT YEARWEEK('2010-3-14',1) 返回 10
其中第二个参数是 mode ,具体指的意思如下: www.2cto.comModeFirst day of weekRangeWeek 1 is the first week …0Sunday0-53with a Sunday in this year1Monday0-53with more than 3 days this year2Sunday1-53with a Sunday in this year3Monday1-53with more than 3 days this year4Sunday0-53with more than 3 days this year5Monday0-53with a Monday in this year6Sunday1-53with more than 3 days this year7Monday1-53with a Monday in this 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 下月第一天;
最新文章
- c# long转 datetime
- Linux用户切换
- Python文件操作题
- 开发Portlet第一步:如何基于Crystal开发静态Portlet?
- context:annotation-config 与context:component-scan
- 论文笔记之:Attention For Fine-Grained Categorization
- hdu 2629 Identity Card (字符串解析模拟题)
- SQL Agent Job ->;>; 通过sys.sysprocesses的program_name字段来定位对应的Job
- [转] When exactly does the virtual table pointer (in C++) gets set for an object?
- projecteuler----&;gt;problem=34----Digit factorials
- Firefox firebug and xpath checker
- 浙大pat 1059 题解
- Redis基本数据类型
- Fullpage.js全屏滚动jQuery插件
- babel 插件编写
- Python OR &; AND
- xhprof 安装详解
- Mac安装LNMP环境,升级php7
- 容器学习笔记之CentOS7安装Docker(安装指定版本的Docker,加速,卸载)
- oracle 导出表