java - fetch records based on today's date -


i wish generate reports application, 1 such report requires display list of orders given today. have following method in ejb returns nothing (debugged , found so):

public collection<orderstock> getorderreport(string username) {    string strquery = null;     strquery = "select o orderstock o o.username.username = :username , o.orderdatetime = :orderdatetime";       collection<orderstock> c = em.createquery(strquery).setparameter("username",username).setparameter("orderdatetime", new date(),temporaltype.date).getresultlist();     return c; } 

how solve it? why return nothing?

edited: using mysql backend datatype of orderdatetime datetime eg os data in orderdatetime : 2012-06-05 00:12:32 2012-06-05 11:34:42 2012-04-05 12:32:45

you have datetime column, , looking posts on single date. suspect datetime column contains seconds or miliseconds since epoch. can't compare times dates, have convert day time. 2 times describe day.

select o  orderstock o       o.username.username = :username      , (         o.orderdatetime >= firstsecondoftheday         or o.orderdatetime <= lastsecondoftheday     ) 

depending on database system can calculate these seconds (or milliseconds, don't know table) using database or rather in java


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -