timestampdiff在mysql与db2中用法
2017-06-08 09:41
393 查看
DB2中使用方式
计算两个时间戳记之间的时差:
–秒的小数部分为单位
values timestampdiff(1,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–秒为单位
values timestampdiff(2,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–分为单位
values timestampdiff(4,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–小时为单位
values timestampdiff(8,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–天为单位
values timestampdiff(16,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–周为单位
values timestampdiff(32,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–月为单位
values timestampdiff(64,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–季度为单位
values timestampdiff(128,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–年为单位
values timestampdiff(256,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
在调用timestampdiff转换的时候,两个日期是必须是日期格式,如果是varchar需要用timestamp来转换,调用timestampdiff转换后的结果是char(22)的类型
MySQL使用方式
函数TimeStampDiff()是MySQL本身提供的可以计算两个时间间隔的函数,语法为:
(microseconds),
计算两个时间戳记之间的时差:
–秒的小数部分为单位
values timestampdiff(1,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–秒为单位
values timestampdiff(2,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–分为单位
values timestampdiff(4,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–小时为单位
values timestampdiff(8,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–天为单位
values timestampdiff(16,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–周为单位
values timestampdiff(32,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–月为单位
values timestampdiff(64,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–季度为单位
values timestampdiff(128,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
–年为单位
values timestampdiff(256,char(current timestamp - timestamp(’2010-01-01-00.00.00’)));
在调用timestampdiff转换的时候,两个日期是必须是日期格式,如果是varchar需要用timestamp来转换,调用timestampdiff转换后的结果是char(22)的类型
MySQL使用方式
函数TimeStampDiff()是MySQL本身提供的可以计算两个时间间隔的函数,语法为:
TIMESTAMPDIFF(,unit,[code]datetime_expr1
datetime_expr2),其中unit单位有如下几种,分别是:[/code]FRAC_SECOND
(microseconds),
SECOND,
MINUTE,
HOUR,
DAY,
WEEK,
MONTH,
QUARTER, or
YEAR
相关文章推荐
- timestampdiff在mysql与db2中用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法
- mysql timestampdiff的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL的时间差函数TIMESTAMPDIFF、DATEDIFF的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
- mysql 计算两个时间差函数(TIMESTAMPDIFF)的用法
- MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法