MySQL的YEARWEEK函数以及查询本周数据
2013-03-10 16:45:10     我来说两句      作者:kamuikyo
收藏    我要投稿
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.com  
 
Mode
First day of week
Range
Week 1 is the first week …
0
Sunday
0-53
with a Sunday in this year
1
Monday
0-53
with more than 3 days this year
2
Sunday
1-53
with a Sunday in this year
3
Monday
1-53
with more than 3 days this year
4
Sunday
0-53
with more than 3 days this year
5
Monday
0-53
with a Monday in this year
6
Sunday
1-53
with more than 3 days this year
7
Monday
1-53
with 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 下月第一天;
 

最新文章

  1. c# long转 datetime
  2. Linux用户切换
  3. Python文件操作题
  4. 开发Portlet第一步:如何基于Crystal开发静态Portlet?
  5. context:annotation-config 与context:component-scan
  6. 论文笔记之:Attention For Fine-Grained Categorization
  7. hdu 2629 Identity Card (字符串解析模拟题)
  8. SQL Agent Job ->> 通过sys.sysprocesses的program_name字段来定位对应的Job
  9. [转] When exactly does the virtual table pointer (in C++) gets set for an object?
  10. projecteuler---->problem=34----Digit factorials
  11. Firefox firebug and xpath checker
  12. 浙大pat 1059 题解
  13. Redis基本数据类型
  14. Fullpage.js全屏滚动jQuery插件
  15. babel 插件编写
  16. Python OR & AND
  17. xhprof 安装详解
  18. Mac安装LNMP环境,升级php7
  19. 容器学习笔记之CentOS7安装Docker(安装指定版本的Docker,加速,卸载)
  20. oracle 导出表

热门文章

  1. java新手笔记18 类比较
  2. Core Canvas–Day1
  3. spring mvc 笔记
  4. 00_ForTest
  5. Flash Professional CS6 安装zxp插件
  6. go build 时报错 cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
  7. leetcode problem 32 -- Longest Valid Parentheses
  8. Unix环境高级编程学习笔记——fcntl
  9. Python3 模块
  10. 列表字体css