-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Compare TimeStamp field with String
PostPosted: Mon Mar 01, 2004 2:51 pm 
Newbie

Joined: Wed Jan 28, 2004 5:21 pm
Posts: 18
Location: Maracaibo, VZLA
Hi, I'm new using Hibernate and HQL and I'm trying to select all records that was created in a specific date. When I run for example

select myTable.TimeStampField from MyTable as myTable
where myTable.TimeStampField = '2004-02-12'


it didn't show me anything. I think it is because I'm comparing a timestamp field 2004-02-12 09:54:12.0 with a simple string 2004-02-12.
My questions is: Is this the problem or what is the problem with the sentence ? How can I compare a TimeStamp with a string? or even better How can I do what I want to do ???

Thanks in advance
Alejandro.-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 3:04 pm 
Newbie

Joined: Wed Jan 28, 2004 5:21 pm
Posts: 18
Location: Maracaibo, VZLA
I forgot, I'm using SQLserver 2000

Alejandro.-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 3:26 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
I would probably do something like this...

Code:
GregorianCalendar cal = new GregorianCalendar();
cal.set(GregorianCalendar.YEAR, 2004);
cal.set(GregorianCalendar.MONTH, 2);
cal.set(GregorianCalendar.DATE, 12);
         
Timestamp ts = new Timestamp(cal.getTime().getTime());

String hqlString = "select myTable.TimeStampField from MyTable as myTable where myTable.TimeStampField = :targetTimeStamp";

Query query = session.createQuery(hqlString);
query.setTimestamp("targetTimeStamp",ts);
            
List list = query.list();


You will probably need to do something like....
... where myTable.TimeStampField > :ts1 and myTable.TimeStampField < :ts2

and have ts1 = '2004-02-11' and ts2 = '2004-02-13' since
'2004-02-12' clearly does not equal 2004-02-12 09:54:12.0

Hope this helped.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 8:02 am 
Newbie

Joined: Wed Jan 28, 2004 5:21 pm
Posts: 18
Location: Maracaibo, VZLA
Thank you tcollins, but if there any other way to do this ? For example in SQL I can do this:

Select CO_SOCIEDAD, MO_TOTAL, NU_DOC_COMPENSACION
from log_evento WHERE CO_CTA= 121001251
AND NO_TRANSACCION = 'T4' AND
STR(YEAR(FE_TRANSACCION),4,0)+
REPLICATE('0',2 - LEN(MONTH(FE_TRANSACCION)))+
RTRIM(CAST(MONTH(FE_TRANSACCION) AS CHAR(2)))+
REPLICATE('0',2 - LEN(DAY(FE_TRANSACCION)))+RTRIM(CAST(DAY(FE_TRANSACCION) AS CHAR)) = '20040212'


FE_TRANSACCION is a TimeStamp fields and I converted it to string....

Is there any way to do this in HQL ???

greetings
Alejandro.-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.