vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi folks, when subtracting 2 timestamps from each other the result is duration. () But in DB2 the format is a bit funny: lets say we have 59,5 seconds. If we have one second more, the result is: 100,5. This mechanism works for seconds, minutes, hours, days. months and years. That would be OK if we always have the same number of days a month - which does not reflect our calendar. How many days has a month in the result? What is with leap years? When I add 1 year to Feb. 29th this year, what is the result? And when I subtract it from Feb. 29th this year, what is the result? Is there a conversion to seconds and microseconds only? I need it because I have calculate averages of runtimes... Here also a result which is incorrect: db2 "values ( timestamp('2008-02-28-12.00.00') + 1 year , timestamp('2008-02-29-12.00.00') + 1 year)" 1 2 -------------------------- -------------------------- 2009-02-28-12.00.00.000000 2009-02-28-12.00.00.000000 1 record(s) selected. It's clearly not the same when I add 1 year to two different dates... |
| |||
| Is DAYS() what you are looking for? http://publib.boulder.ibm.com/infoce.../r0000789.html Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab |
| ||||
| Thanks Serge, that's a hint... it would be good to have a conversion (or setting db2set) for timestamp calculations in seconds with the microseconds. With days() you can fiddle around - but it's not handy. KISS (keep it simple and stupid) : timestamp calculation should return : seconds,microseconds Anyhow - I started with pure SQL and came to this topic.. beside I also need some logic around - so I did it with a perl script and calculated the duration with timelocal(). Thanks, Stefan p.s. buggy brain : I can't remember the format of duration in PEARL (but there duration is a special data type - very nice design btw...) |