MySQL 时间戳(Timestamp)函数
1. MySQL 获得当前时间戳函数:current_timestamp, current_timestamp()
mysql> select current_timestamp,
current_timestamp();
+---------------------+---------------------+
| current_timestamp | current_timestamp() |
+---------------------+---------------------+
| 2008-08-09 23:22:24 | 2008-08-09 23:22:24 |
+---------------------+---------------------+
2. MySQL (Unix 时间戳、日期)转换函数:
unix_timestamp(),
unix_timestamp(date),
from_unixtime(unix_timestamp),
from_unixtime(unix_timestamp,format)
下面是示例:
select unix_timestamp(); -- 1218290027
select unix_timestamp('2008-08-08'); -- 1218124800
select unix_timestamp('2008-08-08 12:30:00'); -- 1218169800
select from_unixtime(1218290027); -- '2008-08-09 21:53:47'
select from_unixtime(1218124800); -- '2008-08-08 00:00:00'
select from_unixtime(1218169800); -- '2008-08-08 12:30:00'
select from_unixtime(1218169800, '%Y %D %M %h:%i:%s %x'); -- '2008
8th August 12:30:00 2008'
3. MySQL 时间戳(timestamp)转换、增、减函数:
timestamp(date) -- date to timestamp
timestamp(dt,time) -- dt + time
timestampadd(unit,interval,datetime_expr) --
timestampdiff(unit,datetime_expr1,datetime_expr2) --
请看示例部分:
select timestamp('2008-08-08'); -- 2008-08-08 00:00:00
select timestamp('2008-08-08 08:00:00', '01:01:01'); -- 2008-08-08
09:01:01
select timestamp('2008-08-08 08:00:00', '10 01:01:01'); --
2008-08-18 09:01:01
select timestampadd(day, 1, '2008-08-08 08:00:00'); -- 2008-08-09
08:00:00
select date_add('2008-08-08 08:00:00', interval 1 day); --
2008-08-09 08:00:00
MySQL timestampadd() 函数类似于 date_add()。
select timestampdiff(year,'2002-05-01','2001-01-01'); -- -1
select timestampdiff(day ,'2002-05-01','2001-01-01'); -- -485
select timestampdiff(hour,'2008-08-08 12:00:00','2008-08-08
00:00:00'); -- -12
select datediff('2008-08-08 12:00:00', '2008-08-01 00:00:00'); --
7
MySQL timestampdiff() 函数就比 datediff() 功能强多了,datediff()
只能计算两个日期(date)之间相差的天数。
MySQL 时间戳(Timestamp)函数的更多相关文章
- mysql 时间戳格式化函数FROM_UNIXTIME和UNIX_TIMESTAMP函数的使用说明
我们一般使用字段类型int(11)时间戳来保存时间,这样方便查询时提高效率.但这样有个缺点,显示的时间戳,很难知道真实日期时间. MySQL提供了一个时间戳格式化函数from_unixtime来转换格 ...
- mysql 时间戳格式化函数from_unixtime使用说明
我们一般使用字段类型int(11)时间戳来保存时间,这样方便查询时提高效率.但这样有个缺点,显示的时间戳,非常难知道真实日期时间. mysql提供了一个时间戳格式化函数from_unixtime来转换 ...
- [转]MySQL日期与时间戳常用函数
本文原文地址:https://www.cnblogs.com/jhy-ocean/p/5560857.html 平时比较常用的时间.字符串.时间戳之间的互相转换,虽然常用但是几乎每次使用时候都喜欢去搜 ...
- MYSQL时间戳和日期相互转换 笔记整理
相关函数: date_format(date, format) 函数,MySQL日期格式化函数date_format() unix_timestamp() 函数 str_to_date(str, fo ...
- MySQL 时间戳(Timestamp)函数
1. MySQL 获得当前时间戳函数:current_timestamp, current_timestamp() mysql> select current_timestamp, curren ...
- mysql之TIMESTAMP(时间戳)用法详解
一.TIMESTAMP的变体 TIMESTAMP时间戳在创建的时候可以有多重不同的特性,如: 1.在创建新记录和修改现有记录的时候都对这个数据列刷新: ? 1 TIMESTAMP DEFAULT CU ...
- mysql之TIMESTAMP(时间戳)用法详解 [http://www.jb51.net/article/51794.htm]
一.TIMESTAMP的变体 TIMESTAMP时间戳在创建的时候可以有多重不同的特性,如: 1.在创建新记录和修改现有记录的时候都对这个数据列刷新: TIMESTAMP DEFAULT CURREN ...
- FROM_UNIXTIME 格式化MYSQL时间戳函数
FROM_UNIXTIME 格式化MYSQL时间戳函数 对MYSQL没有进行过深入的研究,基础知识匮乏,一遇到问题只能手册,看来要把MYSQL的学习安排进时间表了. 函数:FROM_UNIXTIME作 ...
- MySQL时间戳和时间格式转换函数
MySQL时间戳和时间格式转换函数:unix_timestamp and from_unixtime unix_timestamp将时间转化成时间戳格式.from_unixtime将时间戳转化成时间格 ...
随机推荐
- Mysql查找如何判断字段是否包含某个字符串
Mysql查找如何判断字段是否包含某个字符串 有这样一个需求,在Mysql数据库字符串字段(权限)中,用户有多个不同的邮箱,分别被‘,’分开,现在要取出某个邮箱的所有成员列表. 假设有个表: ...
- 遇到java.lang.OutOfMemoryError: Java heap space问题【持续跟踪中...】
昨天下午app服务端无缘无故又502错了,我打开tomcat 日志: INFO: org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: i ...
- mysql2redis
mysql2redis这个项目主要解决mysql数据跟redis数据同步的问题 目前在测试环境研究这方面的应用,以下是git上面的介绍 git入口 git安装入口 Dependencies pl ...
- 数字证书KeyTool使用(第二篇)
http://my.oschina.net/frankies/blog/344914 J2SDK提供了keytool命令行工具,可以根据指定的参数来创建数字证书.生成的证书或证书库默认保存在命令行当前 ...
- Cocos2d 3.0继承自Sprite的类在addChild后出现故障
当继承自Sprite的类被addChild到其它的Node里后出现例如以下图问题,说明没有调用父类Sprite::init()的方法.由于父类Sprite里的_textureAtlas须要初始化为nu ...
- Matlab mex编程
经典教程:mex 编程 http://classes.soe.ucsc.edu/ee264/Fall11/cmex.pdf Matlab 快速编程: http://www.ee.columbia.ed ...
- richTextBox插入表格
附件:http://files.cnblogs.com/xe2011/richTextBox_InsertTable.rar 插入表格 /// <summary> /// 插入表格 /// ...
- [rxjs] Throttled Buffering in RxJS (debounce)
Capturing every event can get chatty. Batching events with a throttled buffer in RxJS lets you captu ...
- LVM物理卷命令
1. 物理卷命令 一般维护命令: #pvscan //在系统的全部磁盘中搜索已存在的物理卷 #pvdisplay 物理卷全路径名称 //用于显示指定物理卷的属性. #pvdata 物理卷全路径名 ...
- abap中的弹出窗体函数
POPUP_TO_CONFIRM_WITH_MESSAGE 会话框确实处理步骤; 用识别正文POPUP_TO_SELECT_MONTH 日历:弹出 POPUP_TO_C ...