Home > Database > Mysql Tutorial > sql 时间日期加减处理函数

sql 时间日期加减处理函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:48:46
Original
2051 people have browsed it

分享一篇在sql中的一些常用的时间日期处理函数,包括有-DATEPART DATEDIFF CONVERT getdate() DATEADD几个函数

--获取当前时间
Select getdate()
--获取当前年月日 YY代表年,MM代表月,DD代表日,hh代表时,ss代表秒
/*

 代码如下 复制代码

year yy 1753--9999 quarter qq 1--4 month mm 1--12 day of year dy 1--366

day dd 1--31 week wk 1--53 weekday dw 1--7(Sunday--Saturday)

hour hh 0--23 minute mi 0--59 second ss 0--59 milisecond ms 0--999 */
--DATEPART与DATENAME实现差不多,都能实现同样效果,DATEPART返回的是整数,DATENAME返回的是字符

 代码如下 复制代码
Select DATEPART(qq,getdate())

--获取前时间的前几天 -d ;后几天 +d

 代码如下 复制代码
Select getdate()-1

--获得两段时间相距的几年 yy,几月 mm,几日 dd

 代码如下 复制代码
Select DATEDIFF(dd,'2011-7-7',getdate())

--将字符串类型的日期转为日期类型的

 代码如下 复制代码
Select CONVERT (DATETIME,'2011-8-6'))

--在当前时间上加上或减去年月日

 代码如下 复制代码
Select DATEADD(mm,-2,getdate())
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template