-->
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.  [ 2 posts ] 
Author Message
 Post subject: problems with trunc date
PostPosted: Mon Jul 05, 2010 11:29 pm 
Newbie

Joined: Mon Jul 05, 2010 10:48 pm
Posts: 1
Hi all,

I am trying to convert a sql query into hql, and in the original sql query, it has the where condition like "where cast(convert(varchar,created_on,112) as datetime) between ? and ?...."

basically, the idea is to compare the date without considering the time differrence, e.g.

in db created_on is 2010-06-30 12:12:12, and what I want is 2010-060-30 00:00:00.

what I did is replace the question marks with ":date1" and ":date2",but it fails to execute the hql, with the exception that "org.hibernate.QueryException: cast() requires two arguments "
But it is quite likely hibernate doesn't support this convert() function. does anyone know some better way on how to convert this query?

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: problems with trunc date
PostPosted: Tue Jul 06, 2010 2:46 am 
Newbie

Joined: Wed Nov 04, 2009 5:58 am
Posts: 3
Hi,

You can use NHibernate session.Criteria for this type of datetime checking with database table column.
Please see below statement for ex:

session.CreateCriteria(typeof(<table entity name>))
.Add(Expression.Eq("entrydate<column of the table>", DateTime.Add( new TimeSpan(00, 00, 00))))

may be it will help you. If i am wrong please let me know.

Thank Q.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.