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标量函数-日期函数的更多相关文章

  1. 第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;  ...

  2. javascript函数一共可分为五类: ·常规函数 ·数组函数 ·日期函数 ·数学函数 ·字符串函数

    javascript函数一共可分为五类:    ·常规函数    ·数组函数    ·日期函数    ·数学函数    ·字符串函数    1.常规函数    javascript常规函数包括以下9个 ...

  3. SQL 标量函数-----日期函数datediff()、 day() 、month()、year()

    select day(createtime) from life_unite_product     --取时间字段的天值 select month(createtime) from life_uni ...

  4. SQL 标量函数-----日期函数 day() 、month()、year()

    select day(createtime) from life_unite_product --取时间字段的天值 select month(createtime) from life_unite_p ...

  5. SQL 标量函数-----日期函数 day() 、month()、year() 转载

      select day(createtime) from life_unite_product     --取时间字段的天值 select month(createtime) from life_u ...

  6. sql数据库中日期函数---2017-04-12

    一.SQLServer时间日期函数详解 1.  当前系统日期.时间 select getdate() 2. dateadd      在向指定日期加上一段时间的基础上,返回新的 datetime 值 ...

  7. MySQL 进阶4 SQL常见函数: 字符函数/数学函数/日期函数/流程控制函数(if/case)

    # 进阶4 SQL常见函数 分类: 1/单行函数: 字符函数: concat(),length(),ifnull(__,default) ,instr(), trim(),upper(),lower( ...

  8. SQL servcer 时间日期函数、数据类型转换

    1.时间日期函数 2.数据类型转换 3.习题 建立两个表,一个部门表,一个人员表.部门:部门的编号,部门的名称,部门的职责.人员:人员的编号,姓名,年龄,性别,cid所属部门

  9. Sql server DATEADD日期函数的使用

    DATEADD日期函数 DATEADD() 函数在日期中添加或减去指定的时间间隔. 日:在当前日期上加两天 , ,'2014-12-30') 月:在当前日期上加两个月 , , 年:在当前日期上加两年 ...

随机推荐

  1. Apache 处理svg工具包Apache(tm) Batik SVG Toolkit

    Apache™ Batik SVG Toolkit¶ Overview¶ Batik is a Java-based toolkit for applications or applets that ...

  2. 还原数据库出现“未获得排他訪问”解决方法(杀死数据库连接的存储过程sqlserver)

    在master数据库下创建存储步骤例如以下: createproc killspid (@dbnamevarchar(20)) as begin declare@sqlnvarchar(500) de ...

  3. IntelliJ 中类似于Eclipse ctrl+o的是ctrl+F12

    IntelliJ 中类似于Eclipse ctrl+o的是ctrl+F12 学习了:https://blog.csdn.net/sjzylc/article/details/47979815

  4. [LeetCode][Java] Subsets

    题目: Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset ...

  5. unique函数(STL)

    unique()函数是一个去重函数,STL中unique的函数 unique的功能是去除相邻的重复元素(只保留一个),还有一个容易忽视的特性是它并不真正把重复的元素删除.他是c++中的函数,所以头文件 ...

  6. 2016/05/06 Sublime Text 3 常用插件以及安装方法(转)

    http://www.cnsecer.com/460.html 安装Sublime Text 3插件的方法: 朋友们,小站活着不容易,全靠广告费养着了,如果本文对你有帮助.麻烦动下手点下页面的广告吧, ...

  7. handsontable整理

    hansontable简介 hansontable是一个在线类似Excel的表格编辑器,支持丰富的展现和交互,有多样的单元格类型供配置. 核心是由原生JavaScript构建,充分模块化,支持自定义b ...

  8. CRM 2011 开发中遇到的问题小结

    1.将Retrive 方法改成 RetrieveMultiple时 如果指定的ColumnSet 没有指定主键(entiryname+id),要显示增加实体的主键.否则在调用 Retrieve方法时返 ...

  9. UVA10600 ACM Contest and Blackout —— 次小生成树

    题目链接:https://vjudge.net/problem/UVA-10600 In order to prepare the “The First National ACM School Con ...

  10. 计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排

    1005 ACM组队安排 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pro ...