-->
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: Comparing a timestamp date with a string date
PostPosted: Thu Sep 15, 2005 8:55 am 
Newbie

Joined: Tue Aug 02, 2005 10:36 pm
Posts: 5
Hi all,


I've the following code:


Query query = dbSession.createQuery("from Job as job where job.dateCollected >= :dateStart");

query.setTimestamp("dateStart", DateTimeUtil.parse((String) request.getParameter("dateStart")).toDate());

It works fine if the dateCollected field is a Date Object in my Job class
Due to unforseen stuff, dateCollected has to be changed to a String Object.

How should i change the query?

The dateStart parameter is gotten from a text field in ddMMyyyy format (eg:15092005).

Thanks.


Top
 Profile  
 
 Post subject: Re: Comparing a timestamp date with a string date
PostPosted: Thu Sep 15, 2005 9:42 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
kenni81 wrote:
It works fine if the dateCollected field is a Date Object in my Job class
Due to unforseen stuff, dateCollected has to be changed to a String Object.


Storing dates as varchars is not a good idea. You could use a function to cause the dbms to convert the string into a date so the query executes sensibly, but what you really want to do is use a sensible database schema.


Top
 Profile  
 
 Post subject: compare date in string format with a date object
PostPosted: Thu Sep 15, 2005 11:33 am 
Newbie

Joined: Tue Aug 02, 2005 10:36 pm
Posts: 5
Its the user's request to use the ddMMyyyy format in the web interface. I wanted to save on convert back and forth the date if i used a datetime object in the dbms thus i used string.

Now i need to compare this string with a date object parameter to the query.Any temporary casting or conversion functions which i can use in HQL.Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 6:24 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
From my reply to your other post:

The easied fix I could see would be store the date in yyyyMMdd that way the higher string is the later date and just present in what ever format you want.

You can then set date start when you compare it to be a string in that format with simpledateformater.


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.