Jooqer
Jooqer

Reputation: 21

Convert given time to seconds in jooq framework

Suppose time is given in HH:MM:SS format.how can we convert this time to second in jooq.

example- Input Time - 2:10:30 outlet- 2*60*60 + 10*60 + 30 =7830 secs

Upvotes: 1

Views: 161

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221031

This works in both MySQL and PostgreSQL, assuming you're using the TIME data type (otherwise, use DSL.time() to convert your data to SQL TIME):

with t(v) as (select time '02:10:30')
select extract(hour from v) * 3600
     + extract(minute from v) * 60
     + extract(second from v)
from t

jOOQ version:

hour(v).times(inline(3600))
  .plus(minute(v).times(inline(60)))
  .plus(second(v))

The following import is implied, as always:

import static org.jooq.impl.DSL.*;

Upvotes: 0

Related Questions