-->
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.  [ 5 posts ] 
Author Message
 Post subject: UK Dates
PostPosted: Thu Mar 09, 2006 1:01 pm 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
I am having a problem compairing dates with NHibernate:

For example i have this named query

Code:
<query name="Fair.GetOngoing">from Fair where starting_date &lt;= ? and end_date &gt;= ?</query>


I have a date stored in my db 08/03/2006 (which is in the United Kingdom ddmmyyyy format) but when is compare this with the current shortdatetime Derived from System.DateTime.Now.ToShortDateString(); which is 09/03/2006 also in ddmmyyyy.

"starting_date &lt;= ?" nhibernate Is evaluating this to false and it only appears to evaluate to ture when i change the stored start date to 03/09/2006 so i appear hibernate is converting it to us style.

How do i fix this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 4:45 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Anyone got any help with this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 4:49 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
bosh wrote:
Anyone got any help with this?

What is the DB field type of affected fields?
And Are You assigning string or date value to the parameter? If string, try converting it to date and assign converted value to param.

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 11:18 am 
Newbie

Joined: Thu May 19, 2005 6:04 am
Posts: 14
Location: Glasgow, UK
I use queries with named params, then assign UK dates (e.g. -

IQuery q = CurrentSession.CreateQuery(queryToExecute);

//add the date params
q.SetParameter("StartDate",StartDate);
q.SetParameter("EndDate",EndDate);
)
I've never had any problems. Are you using datetime variables, or are you parsing strings?

Mark


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 12:15 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Yes, named parameters work much better for dates, in my experience.


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