How can I convert the current timestamp ( or any other date of the format 2010-05-21-00.00.00.000000) to an integer. For example, I want to convert 2010-05-21-05.32.42.000000 to 1274419962 ( number of seconds since 1/1/1970)... is there a function that will do this for me?
Sometimes, you need to know how the difference between two timestamps. For this, DB2 provides a built in function called TIMESTAMPDIFF(). The value returned is an approximation, however, because it does not account for leap years and assumes only 30 days per month.
Using timestampdiff() is more accurate when the dates are close together than when they are far apart. If you need a more precise calculation, you can use the following to determine the difference in time (in seconds):
For convenience, you can also create an SQL user-defined function of the above:
CREATE FUNCTION secondsdiff(t1 TIMESTAMP, t2 TIMESTAMP)