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 标量函数-----日期函数 day() 、month()、year() 转载的更多相关文章

  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标量函数-日期函数

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

  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 server DATEADD日期函数的使用

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

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

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

随机推荐

  1. java-day23

    事务的四大特征: 1.原子性:是不可分割的最小操作单位,要么同时成功,要么同时失败. 2.持久性:当事务提交或回滚后,数据库会持久化的保存数据. 3.隔离性:多个事务之间,相互独立. 4.一致性:事务 ...

  2. transport error 202: bind failed: Address already in use

    background: I have terminated some test debugger without properly saying goodbye. the JDWP didn't cl ...

  3. 结对编程UI

    GitHub:https://github.com/zsl1996/UI/commits/master 一.            实验内容 这是交付给最终用户的软件,有一定的界面和必要的辅助功能.完 ...

  4. Python 文件名

  5. ulimit - 获取和改变用户的限制设定

    大纲 #include <ulimit.h> long ulimit(int cmd, long newlimit); 描述 警告: 这个函数已经被废弃. glibc 不再提供这个包含文件 ...

  6. leetcood学习笔记-112-路径总和

    题目描述: 第一次提交: class Solution(object): def hasPathSum(self, root, sum): """ :type root: ...

  7. webstorm常见快捷方法与遇到的一些问题

    1.动态添加标签快捷写法 例子:生成10个文字按顺序编号的class为task-item的div 2.win10下webstorm的terminal无法输入? 打开一个 cmd.exe,标题栏 右键 ...

  8. thinkphp 日志驱动

    日志驱动默认的命名空间位于Think\Log\Driver,驱动类需要实现的接口方法包括: 方法 说明 架构方法 __construct($config=array()) 写入方法 write($lo ...

  9. composer(作曲家)安装php-ml

    刚开始我用的是up5.6版本php命令安装composer 后来使用composer时发现命令行会提示php版本太低 于是我下载了wamp,使用7.1版本的php重新安装了composer,因为php ...

  10. 39 Ubuntu下配置python的vscode开发环境

    0 引言 最近想在ubuntu下搞深度学习,首先配置了python的vscode开发环境.在配置python时,选择了Anaconda3.x,保证了其相对于系统python2.x的独立性.另外,vsc ...