hibernate - HQl query to get week of the year -


i need make following mssqlserver query gets number of changes made in current weeek

select count(1) audit_tbl datepart( wk, action_time)=datepart( wk,getdate()) 

i strucked functiondatepart( wk, action_time)=datepart( wk,getdate()) there equivalent in hql.

also there way date(2014-03-24) part 2014-03-24 20:56:26.297 in hql

update:

select dateadd(day,datediff(day,0,action_time),0) actiondate, count(1) total  server_tbl year(action_time) = year(getdate()) group dateadd(day,datediff(day,0,action_time),0) 

it gives records group actiontime(stored in db timestamp)

i don't think there week() function in hql. , cannot mix hql , sql.

therefore, can either use sql query or switch criteria queries , implement own sqlcriterion produce exact sql fragment want (see javadoc here)

update: option missed extract() function. first, must configure hibernate use sqlserverdialect (or 1 of subclasses). extract function translated datepart in sql , following clause should trick :

... extract(wk actiontimeproperty) = extract(wk current_date()) 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -