Home  >  Article  >  Database  >  MySQL中日期和时间戳互相转换的函数和方法_MySQL

MySQL中日期和时间戳互相转换的函数和方法_MySQL

WBOY
WBOYOriginal
2016-06-01 12:59:101053browse

① 时间戳转换成日期

代码如下:


FROM_UNIXTIME


例如:

数据表中 invest_time 存储的是时间戳,如 1429063399

使用 FROM_UNIXTIME 可以把时间戳转换为日期:

代码如下:


select FROM_UNIXTIME(invest_time,'%Y年%m月%d') from crm_invest_apply


执行结果:

② 把日期转换为时间戳,和 FROM_UNIXTIME 正好相反

代码如下:


UNIX_TIMESTAMP


例如:

代码如下:


SELECT UNIX_TIMESTAMP('2015-04-29')


执行结果:

Statement:
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