Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hql query to get records of the week

 
krish bhadragiri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i want to retrieve records of the week (i.e records since last 7days).i wrote
"from WorkDetails as work_details where work_details.dated<=current_date and dated>=currrent_date-7 and work_details.employee_id="+employee_column_id"

but its throwingrg.hibernate.exception.SQLGrammarException:could not execute query.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you set current_date? Should you not be using the current_date() function?
 
krish bhadragiri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually m setting the dates using string date format as '2007-04-19'in dated field of mysql table of colum type date.

so i want querries for retrieving records for last seven days and last 1 month.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this is a Hibernate question, I'm moving it to our Object/Relational forum.
 
David Madouros
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This feels like more a hack than anything, but...

The problem is that mysql converts dates to numerics when you add or subtract. For example, current_date = 2007-04-20, but (current_date + 0) = 20070420. A solution (hack) for this is to do the following:



Ugly, but it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic