Question

I could find something like this to find difference in seconds. But I am not able to find how to find difference in milliseconds.

select (start_time - datetime(2013-08-12 19:05:34.223) year to fraction(3))
    ::interval second(9) to second 
    from table1 where event_id = 1
Was it helpful?

Solution

First , if you really want the milliseconds detail from the database, you need to check if the USEOSTIME parameter is activated (by default isn't).
Informix only show the fractional/milliseconds when the database is configured to use the OS TIME (this means they use the OS gettime() function).
When this option is deactivated the fractional part always be zeros.

If it isn't activated , you or the DBA need to change this at the onconfig file and restart the engine.

Just careful , because this will affect all timestamps used at your datadabase.

select * from sysmaster:sysconfig where cf_name = 'USEOSTIME';
    cf_id         54
    cf_name       USEOSTIME
    cf_flags      0
    cf_original   1
    cf_effective  1
    cf_default    0
    1 row(s) retrieved.

drop table if exists tp01;
    Table dropped.

create temp table tp01 ( dt datetime year to fraction );
    Temporary table created.
insert into tp01 values ( current);
    1 row(s) inserted.

select * from tp01;
    dt
    2013-10-18 08:29:36.864
    1 row(s) retrieved.
select dt, current, (current - dt)::interval second(9) to fraction from tp01;
    dt                      (expression)            (expression)
    2013-10-18 08:29:36.864 2013-10-18 08:29:36.864          0.000
    1 row(s) retrieved.
select dt, current, ((current - dt)::interval second(9) to fraction)*1000 from tp01;
    dt                      (expression)            (expression)
    2013-10-18 08:29:36.864 2013-10-18 08:29:36.865          1.000
    1 row(s) retrieved.

Here, after wait 8 seconds and I re-run the selects above...

dt                      (expression)            (expression)
2013-10-18 08:30:44.539 2013-10-18 08:30:53.058          8.519

dt                      (expression)            (expression)
2013-10-18 08:30:44.539 2013-10-18 08:30:53.058       8519.000

OTHER TIPS

Sorry for java specific code but below is the sql code that can be useful to u :

select (datediff(ss,StartDate,EndDate)*1000)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top