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本身提供的可以计算两个时间间隔的函数,语法为:TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2),其中unit单位有如下几种,分别是:FRAC_SECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR
