New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateDiff #380

Closed
Ghalleb opened this Issue Apr 1, 2013 · 8 comments

Comments

Projects
None yet
2 participants
@Ghalleb

Ghalleb commented Apr 1, 2013

It would be great to have a function that calculate the difference between 2 dates

For my part, I need to know the number of day between 2 datetime, without taking hours/minutes in account. ie 26/12/212 15:12:56 and 22/12/212 05:01:32 would give 4 days. I'm just taking the difference between the date.

In SQL I would use something like that (postgres):

date_part('day', date_trunc('day', end) - date_trunc('day', start))

in MSSQL and Sybase there is the datediff function:

datediff(dd, start, end)

in MySQL it woulf be:

datediff(start, end)

@timowest

This comment has been minimized.

Show comment
Hide comment

@ghost ghost assigned timowest Apr 2, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 2, 2013

Member

PostgreSQL is still missing

Member

timowest commented Apr 2, 2013

PostgreSQL is still missing

timowest added a commit that referenced this issue Apr 3, 2013

timowest added a commit that referenced this issue Apr 3, 2013

timowest added a commit that referenced this issue Apr 3, 2013

timowest added a commit that referenced this issue Apr 3, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 3, 2013

Member

Added datediff to SQLExpressions factory class

Member

timowest commented Apr 3, 2013

Added datediff to SQLExpressions factory class

@Ghalleb

This comment has been minimized.

Show comment
Hide comment
@Ghalleb

Ghalleb Apr 3, 2013

Can you provide a code sample?

Ghalleb commented Apr 3, 2013

Can you provide a code sample?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 3, 2013

Member

Here are the related tests https://github.com/mysema/querydsl/blob/master/querydsl-sql/src/test/java/com/mysema/query/SelectBase.java#L440

You use the DatePart enum to specify the unit and SQLExpressions.datediff(unit, start, end) to create the datediff expression.

Member

timowest commented Apr 3, 2013

Here are the related tests https://github.com/mysema/querydsl/blob/master/querydsl-sql/src/test/java/com/mysema/query/SelectBase.java#L440

You use the DatePart enum to specify the unit and SQLExpressions.datediff(unit, start, end) to create the datediff expression.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 16, 2013

Member

Released in 3.1.1

Member

timowest commented Apr 16, 2013

Released in 3.1.1

@timowest timowest closed this Apr 16, 2013

@Ghalleb

This comment has been minimized.

Show comment
Hide comment
@Ghalleb

Ghalleb May 8, 2013

Hi Timo,

Thanks for the new function.

For my part, I really need the date_trunc part. Or anyway to convert a datetime to a date.

Because if I have date1= 01/01/2013 15:00 and date2 = 02/01/2013 10:00 I need the datediff (date2 - date1) to be 1 day and not 19 hours...

Perhaps am I missing something but I didn't find a way to convert my datetime (DateTimePath<java.sql.Timestamp>) to a date (DatePath<java.sql.Date>) element.

I think it should not be in the datediff function as it works correctly but perhaps in a date_trunc function or in casttodate function.

Ghalleb commented May 8, 2013

Hi Timo,

Thanks for the new function.

For my part, I really need the date_trunc part. Or anyway to convert a datetime to a date.

Because if I have date1= 01/01/2013 15:00 and date2 = 02/01/2013 10:00 I need the datediff (date2 - date1) to be 1 day and not 19 hours...

Perhaps am I missing something but I didn't find a way to convert my datetime (DateTimePath<java.sql.Timestamp>) to a date (DatePath<java.sql.Date>) element.

I think it should not be in the datediff function as it works correctly but perhaps in a date_trunc function or in casttodate function.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 8, 2013

Member

Could you create a new ticket for the date truncation?

Member

timowest commented May 8, 2013

Could you create a new ticket for the date truncation?

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

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