Are there any method to add minute to Timestamp?

618 views
Skip to first unread message

Venkat Sadasivam

unread,
Feb 5, 2014, 9:40:51 AM2/5/14
to jooq...@googlegroups.com
dateAdd method is very helpful to add date but if we want to add minutes to the date then we cannot use dateAdd method in SQL Server. Can you add a new method to add minutes?

Lukas Eder

unread,
Feb 5, 2014, 9:59:01 AM2/5/14
to jooq...@googlegroups.com
Hi Venkat,

In principle, the dateAdd() function should also work for minutes, as it takes a SQL standard interval data type as an argument. For example, you can write:

DSL.dateAdd(DATE_FIELD, DSL.val(new org.jooq.types.DayToSecond(0, 0, 5)));

The above roughly translates to

dateadd(ss, 300, cast([DATE_FIELD] as datetime))

The above works when adding a Java value (bind value) to a field.

I am aware, though, that there is room for many other datetime arithmetic functions. It would probably make sense to support (and emulate) something like:

DSL.dateAdd(Field<? extends Date> date, Field<? extends Number> number, DatePart datePart);

I have registered a feature request for this:

Best Regards,
Lukas

Lukas Eder

unread,
Feb 5, 2014, 11:27:09 AM2/5/14
to jooq...@googlegroups.com
#3009 is now implemented for jOOQ 3.3.0. It was a rather low-hanging fruit. You will be able to add minutes to any DATE_FIELD (or TIMESTAMP_FIELD) as such:

DSL.dateAdd(DATE_FIELD, 5, DatePart.MINUTE);

Best Regards,
Lukas

2014-02-05 Lukas Eder <lukas...@gmail.com>:

Venkat Sadasivam

unread,
Feb 5, 2014, 11:51:26 AM2/5/14
to jooq...@googlegroups.com
Great. I hope it will translate as DATEADD(minute, 5, ?) in SQL Server dialect.

Lukas Eder

unread,
Feb 5, 2014, 12:02:27 PM2/5/14
to jooq...@googlegroups.com
Yes, or more precisely: DATEADD(mm, ?, ?)

Regards,
Lukas


2014-02-05 Venkat Sadasivam <venka...@gmail.com>:
Great. I hope it will translate as DATEADD(minute, 5, ?) in SQL Server dialect.

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Lukas Eder

unread,
Feb 5, 2014, 12:02:47 PM2/5/14
to jooq...@googlegroups.com
I meant DATEADD(mi, ?, ?)


2014-02-05 Lukas Eder <lukas...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages