MySQL--TIMESTAMPDIFF函数
来源:互联网 发布:java获取当前年月日 编辑:程序博客网 时间:2024/06/07 03:54
TIMESTAMPDIFF() function
MySQL the TIMESTAMPDIFF() returns a value after subtracting a datetime expression from another.
It is not necessary that both the expression are of the same type. One may be a date and another is datetime. A date value is treated as a datetime with a default time part '00:00:00'. The unit for the result is given by another argument.
The unit should be one of the following : FRAC_SECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
Syntax :
TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2);
Arguments :
代码实例:
测试数据:
uid
type
code
address地址
phone
bank
bankacct
status
subuid
subtime
chkuid
chktime
1
0
310211111
test
021-111111
test1
10012551111
1
111
2017-04-11 18:41:13
34111
2017-07-21 13:56:58
1
1
2323
2
211
2016-11-08 18:54:01
111
2017-05-18 20:25:43
测试代码:
1.计算相差的天数
SELECTuid,subtime,chktime,TIMESTAMPDIFF(DAY,subtime,chktime) FROM `user_info` whereuid=1
uid
subtime
chktime
TIMESTAMPDIFF(DAY,subtime,chktime)
1
2017-04-11 18:41:13
2017-07-21 13:56:58
100
1
2016-11-08 18:54:01
2017-05-18 20:25:43
191
2.计算相差的年数
SELECTuid,subtime,chktime,TIMESTAMPDIFF(YEAR,subtime,chktime) FROM `user_info` whereuid=1
uid
subtime
chktime
TIMESTAMPDIFF(YEAR,subtime,chktime)
1
2017-04-11 18:41:13
2017-07-21 13:56:58
0
1
2016-11-08 18:54:01
2017-05-18 20:25:43
0
3.计算相差的月数
SELECTuid,subtime,chktime,TIMESTAMPDIFF(MONTH,subtime,chktime) FROM `user_info` whereuid=1
uid
subtime
chktime
TIMESTAMPDIFF(MONTH,subtime,chktime)
1
2017-04-11 18:41:13
2017-07-21 13:56:58
3
1
2016-11-08 18:54:01
2017-05-18 20:25:43
6
- MySQL--TIMESTAMPDIFF函数
- mysql函数TIMESTAMPDIFF和FROM_UNIXTIME
- MYSQL计算时间间隔TimeStampDiff()函数用法
- MYSQL 函数datediff timestampdiff 的区别
- MySQL的时间差函数TIMESTAMPDIFF、DATEDIFF
- MySql中 DATEDIFF 函数 和 TIMESTAMPDIFF 时间 函数
- mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法
- mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- 老树微博,三千诗与画
- 无权最短路径选择
- JavaScript速学记录
- vsftpd服务
- (UVA
- MySQL--TIMESTAMPDIFF函数
- 玲珑杯 1117
- HTML(3)
- php日期转时间戳,指定日期转换成时间戳
- 基于AndFTP完成PC机与Android设备互传文件
- CodeForces
- Curling 2.0 推冰球问题(dfs)
- web.xml使用介绍
- 修改Smartfroms默认文本编辑器