SQL 标量函数----->日期函数 day() 、month()、year()、2009年02月23日 星期一 11:30
SQL 标量函数----->日期函数 day() 、month()、year()、DATEADD()、ATEDIFF()、DATENAME()、DATEPART() GETDATE() 执行实例(表:life_unite_product 有createtime时间字段)
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. Sql server日期函数用法

    SQL日期函数 SQL日期函数中的类型码可以为0,1,2,3,4,5,6,7,8,9,10,11,12,13,14 ,20,21,22,23,24,25,100,101,102,103,104,105 ...

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

  3. SQL Server 日期函数:EOMonth、DateFormat、Format、DatePart、DateName

    一,月份的最后一天 函数 EOMonth 返回指定日期的最后一天 EOMONTH ( start_date [, month_to_add ] ) 1,对于start_date 有两种输入方式,能够转 ...

  4. sql 的实用函数(包含日期函数、截取字符串函数)

    CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() 函数可以用不同的格式显示日期/时间数据. 语法 CONVERT(data_type(length),data_to_b ...

  5. DB2 SQL 日期函数

    DB2 SQL 日期函数1:CURRENT TIMESTAMP 函数:获取当前日期时间语法:CURRENT TIMESTAMP参数:当前日期时间返回值:当前日期时间 2:CURRENT DATE 函数 ...

  6. 数据库开发基础-SQl Server 聚合函数、数学函数、字符串函数、时间日期函数

    SQL 拥有很多可用于计数和计算的内建函数. 函数的语法 内建 SQL 函数的语法是: SELECT function(列) FROM 表 函数的类型 在 SQL 中,基本的函数类型和种类有若干种.函 ...

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

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

  8. Sql server 日期函数和日期转换

    时间函数 SQL Server Date 函数 下面的表格列出了 SQL Server 中最重要的内建日期函数: 函数 描述 GETDATE() 返回当前日期和时间 DATEPART(Type,dat ...

  9. SQL Server日期函数总结

    获得一个月的天数:首先到得一个月最后一天的日期,通过 SQL Server 日期函数 day() 取得日期中的“天 ”部分 获得 2008 年 2 月份的天数:select day(cast('200 ...

随机推荐

  1. VMware中装Win2012并配置Hyper-v

    VMware中装配Win2012再配置Hyper-v,解决虚拟机监控程序已经在运行中的方法 找到虚拟机存放的位置,用记事本打开Windows Server 2012.vmx,在最后添加两行并保存: h ...

  2. Sql总结之Sql--常用函数

    控制流函数 IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境 ...

  3. 答:SQLServer DBA 三十问之六:Job信息我们可以通过哪些表获取;系统正在运行的语句可以通过哪些视图获取;如何获取某个T-SQL语句的IO、Time等信息;

    6. Job信息我们可以通过哪些表获取:系统正在运行的语句可以通过哪些视图获取:如何获取某个T-SQL语句的IO.Time等信息: 我的MSDB数据库中有全部的表: sys.all_columns,s ...

  4. python常用库

    本文由 伯乐在线 - 艾凌风 翻译,Namco 校稿.未经许可,禁止转载!英文出处:vinta.欢迎加入翻译组. Awesome Python ,这又是一个 Awesome XXX 系列的资源整理,由 ...

  5. iOS原型模式

    原型模式:大部分重复,只有一小部分不同的情况下,为了代码清晰和避免麻烦,用原型模式,会更方便一点 // 学生1 StudentModel *stu1 = [[StudentModel alloc] i ...

  6. HTML标签拾遗

    在日常的开发过程中,经常与HTML标签打交道,常用的标签往往是那么几个,在此记录下后续可能会用到的html标签,或许会有意向不到的奇效.全部内容来自w3cschool. <abbr>   ...

  7. 一些对数学领域及数学研究的个人看法(转载自博士论坛wcboy)

    转自:http://www.math.org.cn/forum.php?mod=viewthread&tid=14819&extra=&page=1 原作者: wcboy 现在 ...

  8. Theme皮肤文件(json解析、多文件管理)

    一  官方教程 http://developer.egret.com/cn/github/egret-docs/extension/EUI/skin/theme/index.html 二 thm主题文 ...

  9. 关于spring AOP的学习

    比较好的帖子http://www.cnblogs.com/xing901022/p/4265544.html

  10. Solving “Dynamic Web Module 3.0 requires Java 1.6 or newer” in Maven Projects

    不一定是在Maven Projects里才有这种情况,但解决方法是一样的. 转自:http://qussay.com/2013/09/13/solving-dynamic-web-module-3-0 ...