SQL 截取时间
-- 获取系统时间 print getdate()
-- 获取3天前的时间 print dateadd(day, -3 , getdate())
-- 获取3天后的时间 print dateadd(day, 3 , getdate())
-- 获取3年前的时间 print dateadd(year, -3 , getdate())
-- 获取3年后的时间 print dateadd(year, 3 , getdate())
-- 获取3月后的时间 print dateadd(month, 3 , getdate())
-- 获取9小时后的时间 print dateadd(hour, 9 , getdate()) -- 获取9分钟后的时间 print dateadd(minute, 9 , getdate())
-- 获取指定时间之间相隔多少年 print datediff(year, '2005-01-01', '2008-01-01')
-- 获取指定时间之间相隔多少月 print datediff(month, '2005-01-01', '2008-01-01')
-- 获取指定时间之间相隔多少天 print datediff(day, '2005-01-01', '2008-01-01')
-- 获取指定时间的特定部分 print year(getdate()) print month(getdate()) print day(getdate())
-- 获取指定时间的特定部分 print datepart(year, getdate())
print datepart(month, getdate())
print datepart(day, getdate())
print datepart(hh, getdate())
print datepart(mi, getdate())
print datepart(ss, getdate())
print datepart(ms, getdate())
-- 获取指定时间的间隔部分
-- 返回跨两个指定日期的日期和时间边界数
print datediff(year, '2001-01-01', '2008-08-08') print datediff(month, '2001-01-01', '2008-08-08')
print datediff(day, '2001-01-01', '2008-08-08') print datediff(hour, '2001-01-01', '2008-08-08')
print datediff(mi, '2001-01-01', '2008-08-08') print datediff(ss, '2001-01-01', '2008-08-08')
-- 在向指定日期加上一段时间的基础上,返回新的 datetime 值
print dateadd(year, 5, getdate())
print dateadd(month, 5, getdate())
print dateadd(day, 5, getdate())
print dateadd(hour, 5, getdate())
print dateadd(mi, 5, getdate())
print dateadd(ss, 5, getdate())
-- 获取给定字符串的长度 print len('abcdef')
-- 大小写转换 print lower('ABCDEF') print upper('abcdef')
-- 去空格 print ltrim(' abcd dfd df ') print rtrim(' abcd dfd df ')
转发至微博
转发至微博 SQL 截取时间的更多相关文章
- Sql日期时间格式转换;取年 月 日,函数:DateName()、DATEPART()
一.sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007 ...
- sql 日期时间格式转换
Sql日期时间格式转换 sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, ...
- SQL Server时间粒度系列----第9节时间粒度示例演示
本文目录列表: 1.准备测试数据 2.向测试数据表添加相关时间粒度字段列 3.基于日月季年统计汇总的演示 4.总结语 5.参考清单列表 准备测试数据 为了提供不同时间粒度示例的演示,就需要测试 ...
- SQL Server时间粒度系列----第1节时间粒度概述
本文目录列表: 1.什么是时间粒度?2.SQL Server提供的时间粒度3.SQL Server时间粒度代码演示 4.SQL Server基准日期 5.总结语6.参考清单列表 什么是时间粒度 ...
- SQL Server时间粒度系列----第3节旬、月时间粒度详解
本文目录列表: 1.SQL Server旬时间粒度2.SQL Server月有关时间粒度 3.SQL Server函数重构 4.总结语 5.参考清单列表 SQL Server旬时间粒度 ...
- SQL Server时间粒度系列----第4节季、年时间粒度详解
本文目录列表: 1.SQL Server季时间粒度2.SQL Server年时间粒度 3.总结语 4.参考清单列表 SQL Serve季时间粒度 季时间粒度也即是季度时间粒度.一年每3 ...
- 时间戳转化为时间&&截取时间的年月日
时间戳转化为正常的时间格式 function formatDate(date, fmt) { if (/(y+)/.test(fmt)) { // 在这里 date.getFullYear() + ' ...
- Mybatis设置sql超时时间
开始搭建项目框架的时候,忽略了sql执行超时时间的问题. 原本使用.net开发是,默认的超时时间是30s,这个时间一般一般sql是用不到的,但也不排除一些比较复杂或数据量较大的sql. 而java中, ...
- SQL Server时间类型datetime
SQL Server时间类型datetime 兼容ADO的COleDateTime. SQL datetime 日期和时间数据,可表示1753.1.1 至 9999.12.31的时间,精度为1/300 ...
随机推荐
- python循环导入的解决方案
解决循环import的方法主要有几种: 1.延迟导入(lazy import) 即把import语句写在方法或函数里面,将它的作用域限制在局部. 这种方法的缺点就是会有性能问题. 2. ...
- 【分享】自己写的一个可空的DateTimePicker控件-附源码
最近这段时间在重构以前的一个项目,其中有一项就是要把DateTimePicker控件值可空.大家都知道的DateTimePicker值为DateTime类型,DateTime类型值不能等于Null.但 ...
- github commit, issue, pull request, project
1 github的提供给用户操作和交流的几个对象 commit, issue, pull request and project 2 commit and commit comment commit就 ...
- mybatis 执行查询时报错 【Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: 】
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLE ...
- 《C prime plus (第五版)》 ---第11章 字符串和字符串函数---2
11-3:字符串 输出 三个标准的函数:puts() fputs() printf() 1.puts()函数: #include<stdio.h> #define DEF "I ...
- 【字符串题目】poj 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6193 Accepted: 403 ...
- plugin scala is incompatible with current installation
源文链接:http://stackoverflow.com/questions/31927516/plugin-scala-is-incompatible-with-this-installation ...
- oracle数据库如何备份一张表
--用户名:tms--创建表ts_dictionary的备份create table ts_dictionary_20160715 as select * from ts_dictionary; 补充 ...
- python绘制圆和椭圆
源自:https://blog.csdn.net/petermsh/article/details/78458585 1. 调用包函数绘制圆形Circle和椭圆Ellipse from matplot ...
- HTML5 拖放:在相册中对照片进行排序
1. [代码]index.html <div class="albums"> <div class="album" id=&qu ...