tags:

views:

385

answers:

1

Is there analog og the MySQL's time_to_sec() ?

I heed to perform query like the following on H2 database:

select * from order
join timmingSettings on order.timmingSettings = timmingSettings.id
where (order.time-timmingSettings.timeout) < current_timestamp
+1  A: 

No, but it seems quite easy to add function to h2 if needed.

To convert a timestamp to seconds since epoch, compile and add a Java class to h2's classpath containing:

public class TimeFunc
{
  public static long getSeconds(java.sql.Timestamp ts)
  {
    return ts.getTime() / 1000;
  }
}

The function in the Java code can then be linked in h2 using CREATE ALIAS:

CREATE ALIAS TIME_SECS FOR "TimeFunc.getSeconds";

SELECT TIME_SECS(CURRENT_TIMESTAMP);

Produces:

TIME_SECS(CURRENT_TIMESTAMP())  
1255862217
(1 row, 0 ms)
Filip Korling