timestampdiff mysqlとdb 2での使い方

1437 ワード

DB 2での使用方法
2つのタイムスタンプ間の時差を計算します:--秒の小数部は単位values timestampdiff(1,char(current timestamp-timestamp('2010-01-01-0.00.00'));--秒単位values timestampdiff(2,char(current timestamp-timestamp('2010-01-01-0.00.00'));--単位values timestampdiff(4,char(current timestamp-timestamp('2010-01-01-0.00.00')));--時間単位values timestampdiff(8,char(current timestamp-timestamp('2010-01-01-0.00.00'));--日単位values timestampdiff(16,char(current timestamp-timestamp('2010-01-01-0.00.00'));--週単位values timestampdiff(32,char(current timestamp-timestamp('2010-01-01-0.00.00'));--月単位values timestampdiff(64,char(current timestamp-timestamp('2010-01-01-0.00.00'));--四半期単位values timestampdiff(128,char(current timestamp-timestamp('2010-01-01-0.00.00'));--年単位values timestampdiff(256,char(current timestamp-timestamp('2010-01-01-0.00.00'));
timestampdiff変換を呼び出す場合、2つの日付は日付フォーマットでなければなりません.varcharであればtimestampで変換する必要があります.timestampdiff変換を呼び出すと、char(22)のタイプになります.
MySQLの使い方
関数TimeStampDiff()は、MySQL自身が提供する2つの時間間隔を計算できる関数で、構文は、、TIMESTAMPDIFF(unit、、datetime_expr1、、datetime_expr2)、unit は、FRAC_SECOND (microseconds),  SECONDMINUTEHOURDAYWEEKMONTHQUARTER , or  YEAR