SQL标量函数-日期函数
select day(createtime) from life_unite_product --取时间字段的天值
select month(createtime) from life_unite_product --取时间字段的月值
select year(createtime) from life_unite_product --取时间字段的年值
select datepart(yy,createtime) from life_unite_product --取时间字段的年值
select datepart(qq,createtime) from life_unite_product --取时间字段的季度值
select datepart(mm,createtime) from life_unite_product --取时间字段的月值
select datepart(dy,createtime) from life_unite_product --取时间字段是那年的第几天
select datepart(dd,createtime) from life_unite_product --取时间字段的天值
select datepart(wk,createtime) from life_unite_product --取时间字段是那年的第几个星期
select datepart(dw,createtime) from life_unite_product --取时间字段是那年的那个星期的第几个工作日(工作日从星期日开算)
select datepart(hh,createtime) from life_unite_product --取时间字段的小时值
select datepart(mi,createtime) from life_unite_product --取时间字段的分钟值
select datepart(ss,createtime) from life_unite_product --取时间字段的秒值
select datepart(ms,createtime) from life_unite_product --取时间字段的毫秒值
select dateadd(yy,-1,createtime) from life_unite_product ----取时间字段(年份被减1了)
select dateadd(mm,3,createtime) from life_unite_product ----取时间字段(月份被加3了)
select dateadd(dd,1,createtime) from life_unite_product ----取时间字段(日被加1了)
select DATEDIFF(yy,createtime,getdate()) from life_unite_product --与当前日期的年份差
select DATEDIFF(mm,createtime,getdate()) from life_unite_product --与当前日期的月份差
select DATEDIFF(dd,createtime,getdate()) from life_unite_product --与当前日期的日数差
select DATEDIFF(mi,createtime,getdate()) from life_unite_product --与当前日期的分钟数差
select datename(yy,createtime) from life_unite_product --取时间字段的年值
select datename(mm,createtime) from life_unite_product --取时间字段的月值
select datename(dd,createtime) from life_unite_product --取时间字段的天值
select getdate() --取当前时间
日期函数
1、day(date_expression)
返回date_expression中的日期值
2、month(date_expression)
返回date_expression中的月份值
3、year(date_expression)
返回date_expression中的年份值
4、DATEADD()
DATEADD (, , )
返回指定日期date 加上指定的额外日期间隔number 产生的新日期。参数“datepart” 取值如下:
5、DATEDIFF()
DATEDIFF (, , )
返回两个指定日期在datepart 方面的不同之处,即date2 超过date1的差距值,其结果值是一个带有正负号的整数值。
6、DATENAME()
DATENAME (, )
以字符串的形式返回日期的指定部分此部分。由datepart 来指定。
7、DATEPART()
DATEPART ( datepart , date )
以整数值的形式返回日期的指定部分。此部分由datepart 来指定。
DATEPART (dd, date) 等同于DAY (date)
DATEPART (mm, date) 等同于MONTH (date)
DATEPART (yy, date) 等同于YEAR (date)
下表列出了 datepart 选项以及 SQL Server Compact Edition 所识别的缩写:
日期部分 缩写
年份 yy、yyyy
季度 qq、q
月份 mm、m
每年的某一日 dy、y
日期 dd、d
星期 wk、ww
工作日* dw
小时 hh
分钟 mi、n
秒 ss、s
毫秒 ms
8、GETDATE()
以DATETIME 的缺省格式返回系统当前的日期和时间
SQL标量函数-日期函数的更多相关文章
- 第17课-数据库开发及ado.net 聚合函数,模糊查询like,通配符.空值处理.order by排序.分组group by-having.类型转换-cast,Convert.union all; Select 列 into 新表;字符串函数;日期函数
第17课-数据库开发及ado.net 聚合函数,模糊查询like,通配符.空值处理.order by排序.分组group by-having.类型转换-cast,Convert.union all; ...
- javascript函数一共可分为五类: ·常规函数 ·数组函数 ·日期函数 ·数学函数 ·字符串函数
javascript函数一共可分为五类: ·常规函数 ·数组函数 ·日期函数 ·数学函数 ·字符串函数 1.常规函数 javascript常规函数包括以下9个 ...
- SQL 标量函数-----日期函数datediff()、 day() 、month()、year()
select day(createtime) from life_unite_product --取时间字段的天值 select month(createtime) from life_uni ...
- SQL 标量函数-----日期函数 day() 、month()、year()
select day(createtime) from life_unite_product --取时间字段的天值 select month(createtime) from life_unite_p ...
- SQL 标量函数-----日期函数 day() 、month()、year() 转载
select day(createtime) from life_unite_product --取时间字段的天值 select month(createtime) from life_u ...
- sql数据库中日期函数---2017-04-12
一.SQLServer时间日期函数详解 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值 ...
- MySQL 进阶4 SQL常见函数: 字符函数/数学函数/日期函数/流程控制函数(if/case)
# 进阶4 SQL常见函数 分类: 1/单行函数: 字符函数: concat(),length(),ifnull(__,default) ,instr(), trim(),upper(),lower( ...
- SQL servcer 时间日期函数、数据类型转换
1.时间日期函数 2.数据类型转换 3.习题 建立两个表,一个部门表,一个人员表.部门:部门的编号,部门的名称,部门的职责.人员:人员的编号,姓名,年龄,性别,cid所属部门
- Sql server DATEADD日期函数的使用
DATEADD日期函数 DATEADD() 函数在日期中添加或减去指定的时间间隔. 日:在当前日期上加两天 , ,'2014-12-30') 月:在当前日期上加两个月 , , 年:在当前日期上加两年 ...
随机推荐
- 碧砚适合佳能328 4452 ICD520 4472 4450 硒鼓4700一体机墨盒4770
- 利用WiFi Pineapple Nano渗透客户端获取SHELL
前言: 前两篇文章介绍了The WiFi Pineapple Nano设备的一些主要功能模块,例如PineAP.SSLsplit和Ettercap等.今天给大家实际场景演示下如何利用Pineapple ...
- C#:excel导入导出
资源:excelService 服务 http://download.csdn.net/detail/istend/8060501 排列问题 导出时,数字和字符的排列格式默认不一样,数字靠右,字符靠左 ...
- js中的自定义异常处理函数
1. Can I suppress JavaScript error messages? 2. Can I set up my own JavaScript error handler? 3. Can ...
- android 自己定义水平和圆形progressbar 仅仅定义一些style就能够
效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...
- 深入浅出AOP(一)
动态代理实现AOP: AOP事实上非常早之前依照做出来了一些东西,之所以不敢说做出来了.是由于它是什么?怎么实现?做出来的东西是不是?先前一直查资料.查到的资料跟着做.到后来发现,AOP越来越大,而非 ...
- leetcode——Implement strStr() 实现字符串匹配函数(AC)
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
- 【iOS系列】-iOS的多线程解析
[iOS系列]-iOS的多线程解析 iOS的多线程实现技术: 1:GCD -- Grand Central Dispatch 是基于C语言的底层API 用Block定义任务,使用起来非常灵活便捷 提供 ...
- spring的PROPAGATION_REQUIRES_NEW事务,下列说法正确的是(D)
A:内部事务回滚会导致外部事务回滚 B:内部事务回滚了,外部事务仍可以提交 C:外部事务回滚了,内部事务也跟着回滚 D:外部事务回滚了,内部事务仍可以提交 PROPAGATION_REQUIRES_N ...
- Hadoop Hive概念学习系列之hive里的索引(十三)
Hive支持索引,但是Hive的索引与关系型数据库中的索引并不相同,比如,Hive不支持主键或者外键. Hive索引可以建立在表中的某些列上,以提升一些操作的效率,例如减少MapReduce任务中需要 ...