SQL 语句日期用法及函数 --DAY().MONTH().YEAR()——返回指定日期的天数.月数.年数:select day(cl_s_time) as '日' from class --返回天select '月'=month(cl_s_time) from class --返回月select '年'=year(cl_s_time) from class --返回年 --DATEADD(datepart,number,date)——在日期上增加给定日期类型的数量:select date
SELECT DATE_FORMAT(releaseDate,"%Y年%m月") AS dates,COUNT(*) FROM t_diary GROUP BY DATE_FORMAT(releaseDate,"%Y年%m月") ORDER BY DATE_FORMAT(releaseDate,"%Y年%m月") DESC ;releaseDate 日期 t_diary表名 DATE_FORMAT();按照格式对某个日期操作ORDER BY 排序
使用sql语句查询日期在一周内的数据 select * from ShopOrder where datediff(week,ordTime,getdate()-1)=0 //查询当天日期在一周年的数据 select * from ShopOrder where datediff(day,ordTime,getdate()-1)=0 //查询当天的所有数据 SELECT * FROM A where datediff(d,datetime,getdate()) <=30 //前30天 S
存储过程往拼接的sql语句中传递日期值 declare @start datetime declare @end datetime set @start='2014-3-1' set @end='2014-3-31' ) set @sql=' select * from search_record where (Name!='' or Phone!='') and (thedate between @st and @en )' exec sp_executesql @sql,N'@st date