how to create "where" statement for date and timestamp ?

4,336 views
Skip to first unread message

nabedge

unread,
Nov 9, 2013, 10:34:46 PM11/9/13
to quer...@googlegroups.com
Hi all.
I'm using QueryDSL2.9.x and PostgreSQL9.x .

My table and data is:

 create table foo (
   id int4,
   dt timestamp with time zone
 )
 insert into foo (id,dt) values (1, '2013-11-10T12:34:56');
 insert into foo (id,dt) values (1, '2014-03-04T12:34:56');

I need a SQL like below:

 select id from off where dt::date in ('2013-12-08', '2014-03-04'....(and other date strings) );

The point is that the column type of "dt" is timestamp but I must compare it as "date" without hour, minute, seconds.

 query.from(qFoo).where(qFoo.dt.in ....? what should I coding?...);

I have read the reference manual http://www.querydsl.com/static/querydsl/2.9.0/reference/html/ch03.html
but could not solve my problem.
I will be happy if there were some sample reference book :-)

Timo Westkämper

unread,
Nov 10, 2013, 6:53:07 AM11/10/13
to Querydsl on behalf of nabedge
Hi.

DateTime to Date conversion is available via the SQLExpressions.date methods.

You can use them for example like this

    query.from(qFoo)
            .where(SQLExpressions.date(qFoo.dt).in(date1, date2, ...))

I plan to prepare some cheatsheets for the Querydsl modules.

Timo


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



--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com


nabedge

unread,
Nov 10, 2013, 8:05:48 AM11/10/13
to Querydsl on behalf of Timo Westkämper
Cool !
Thanks Timo.

But Now I use version 2.9.0 .
Anyway I try to version up to 3.2.4 and change my code.
Thank you.


--------
nab...@gmail.com


2013/11/10 Querydsl on behalf of Timo Westkämper <quer...@googlegroups.com>:
> You received this message because you are subscribed to a topic in the
> Google Groups "Querydsl" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/querydsl/MU2p6FoKzgc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

nabedge

unread,
Nov 10, 2013, 8:44:48 AM11/10/13
to Querydsl on behalf of Timo Westkämper
Hi all.
As a matter of fact, I use QueryDSL with Spring-Data-JDBC of
springframework that depends on querydsl-2.9.x .
If you agree, please vote the issue below.
https://github.com/spring-projects/spring-data-jdbc-ext/issues/2

--------
nab...@gmail.com


2013/11/10 nabedge <nab...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages