Implement Date arithmetic #347

Closed
davidbilge opened this Issue Feb 23, 2013 · 10 comments

Comments

Projects
None yet
4 participants
@davidbilge

Currently, it is not possible to do date arithmetic in QueryDSL (see http://stackoverflow.com/q/15026895/537738).

Please add support for some functions like adding intervals (sysdate + 10 days) or subtract dates (SELECT * FROM entity WHERE entity.created < (sysdate - entity.delayInDays)). That would be great!

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 25, 2013

Member

Support is now available via the SQLExpressions.addYears, addMonths, addDays, addHours, addMinutes and addSeconds methods.

e.g. SQLExpressions.addDays(dateField, 10);
Member

timowest commented Feb 25, 2013

Support is now available via the SQLExpressions.addYears, addMonths, addDays, addHours, addMinutes and addSeconds methods.

e.g. SQLExpressions.addDays(dateField, 10);
@davidbilge

This comment has been minimized.

Show comment
Hide comment
@davidbilge

davidbilge Feb 25, 2013

Wow, that was really fast. Is it possible to predict in which version this will surface?

Wow, that was really fast. Is it possible to predict in which version this will surface?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 25, 2013

Member

3.0.0 will be out in a couple of weeks.

Here is temporary solution

DateTemplate.create(Date.class, "{0} + {1s}", dateField, ConstantImpl.create(2));

which would dateField plus 2 days.

Member

timowest commented Feb 25, 2013

3.0.0 will be out in a couple of weeks.

Here is temporary solution

DateTemplate.create(Date.class, "{0} + {1s}", dateField, ConstantImpl.create(2));

which would dateField plus 2 days.

@TuomasKiviaho

This comment has been minimized.

Show comment
Hide comment
@TuomasKiviaho

TuomasKiviaho Feb 27, 2013

Contributor

Would it be possible to add casts between date/time/timestamp as well (not exactly arithmetic I know). It's quite common to have to strip down time part from timestamp and closest thing I found from stackoverflow was to do it via stringValue() which isn't that efficient. This might be already possible in more generic way but I doubt it since there is castToNum(). Would a Sledge Hammer style I-Know-What-I'm-Doing type of blind casting be even possible.

Contributor

TuomasKiviaho commented Feb 27, 2013

Would it be possible to add casts between date/time/timestamp as well (not exactly arithmetic I know). It's quite common to have to strip down time part from timestamp and closest thing I found from stackoverflow was to do it via stringValue() which isn't that efficient. This might be already possible in more generic way but I doubt it since there is castToNum(). Would a Sledge Hammer style I-Know-What-I'm-Doing type of blind casting be even possible.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 27, 2013

Member

@TuomasKiviaho could you create a new ticket for this and maybe add some syntax examples?

Member

timowest commented Feb 27, 2013

@TuomasKiviaho could you create a new ticket for this and maybe add some syntax examples?

@FagnerMartinsBrack

This comment has been minimized.

Show comment
Hide comment
@FagnerMartinsBrack

FagnerMartinsBrack Feb 27, 2013

Needless to say but please create a changelog if any documented feature is going to be broken in a major version pump 😄

Needless to say but please create a changelog if any documented feature is going to be broken in a major version pump 😄

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 27, 2013

Member

@FagnerMartinsBrack this is a new feature, or are you concerned about another feature?

Member

timowest commented Feb 27, 2013

@FagnerMartinsBrack this is a new feature, or are you concerned about another feature?

@FagnerMartinsBrack

This comment has been minimized.

Show comment
Hide comment
@FagnerMartinsBrack

FagnerMartinsBrack Feb 27, 2013

No specific feature I am concerned.
I saw you mentioning v3 so the first thing I thought was backward compatibility. But thinking better the framework has no reason to change too much except for resource names (which can be easly changed) right?

No specific feature I am concerned.
I saw you mentioning v3 so the first thing I thought was backward compatibility. But thinking better the framework has no reason to change too much except for resource names (which can be easly changed) right?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 27, 2013

Member

3.0 has a few changes, but those will all be documented in the release notes and most of them can be resolved via a few naming changes.

Member

timowest commented Feb 27, 2013

3.0 has a few changes, but those will all be documented in the release notes and most of them can be resolved via a few naming changes.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Mar 21, 2013

Member

Released in 3.0.0

Member

timowest commented Mar 21, 2013

Released in 3.0.0

@timowest timowest closed this Mar 21, 2013

@timowest timowest added this to the 3.0.0 milestone Apr 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment