Home > Database > Mysql Tutorial > mysql 时间类型操作_MySQL

mysql 时间类型操作_MySQL

WBOY
Release: 2016-05-31 08:48:14
Original
869 people have browsed it



SELECT year(`date2`),month(`date2`),day(`date2`),time(`date2`) FROM `student` WHERE 1

定义和用法

DATE_ADD() 函数向日期添加指定的时间间隔。

语法

DATE_ADD(date,INTERVAL expr type)

date 参数是合法的日期表达式。expr 参数是您希望添加的时间间隔。

type 参数可以是下列值:

Type 值

MICROSECOND

SECOND

MINUTE

HOUR

DAY

WEEK

MONTH

QUARTER

YEAR

SECOND_MICROSECOND

MINUTE_MICROSECOND

MINUTE_SECOND

HOUR_MICROSECOND

HOUR_SECOND

HOUR_MINUTE

DAY_MICROSECOND

DAY_SECOND

DAY_MINUTE

DAY_HOUR

YEAR_MONTH

实例

假设我们有如下的表:

OrderId

ProductName

OrderDate

1

'Computer'

2008-12-29 16:25:46.635

现在,我们希望向 "OrderDate" 添加 2 天,这样就可以找到付款日期。

我们使用下面的 SELECT 语句:

SELECT OrderId,DATE_ADD(OrderDate,INTERVAL 2 DAY) AS OrderPayDate

FROM Orders

结果:

OrderId

OrderPayDate

1

2008-12-31 16:25:46.635

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template