MySQL 时间戳(Timestamp)函数
2014-11-20 18:13
369 查看
1. MySQL 获得当前时间戳函数:current_timestamp, current_timestamp()
2. MySQL (Unix 时间戳、日期)转换函数:
下面是示例:
3. MySQL 时间戳(timestamp)转换、增、减函数:
请看示例部分:
MySQL timestampdiff() 函数就比 datediff() 功能强多了,datediff()只能计算两个日期(date)之间相差的天数。
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'); -- '20088th 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-0809: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-0908: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-0800: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 时间戳(Timestamp)函数
- mysql 时间字段的函数 timestamp
- MySql中 DATEDIFF 函数 和 TIMESTAMPDIFF 时间 函数
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- MySQL 时间戳(Timestamp)函数
- Mysql日期时间类型(DATE,DATETIME,TIMESTAMP)和函数及与linux系统时间之间的转换(UNIX_TIMESTAMP、FROM_UNIXTIME)
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- MySql最简单的办法格式化日期和 时间( timestamp), 自定义时间函数快速格式化成年月日,时分秒
- MySQL 时间戳(Timestamp)函数
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- MySQL 时间戳(Timestamp)函数
- 查看MySql时间函数:DATE_SUB、DATE_ADD、UNIX_TIMESTAMP等函数的用法
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- MySQL 时间戳(Timestamp)函数
- mysql时间格式函数:from_unixtime()、unix_timestamp()、date_format()
- mysql 中 unix_timestamp,from_unixtime 时间戳函数
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- MySql计算两日期时间之间相差的天数,秒数,分钟数,周数,小时数 计算两日期时间之间相差的天数,秒数,分钟数,周数,小时数,这里主要分享的是通过MySql内置的函数 TimeStampDiff()
- MySQL 时间戳(Timestamp)函数