java - Determine if a given timestamp is within the same day in postgresql -


i've got postgresql table "timestamp without time zone" field. @ given point query table, , need records timestamp within same day when query performed. here code:

 datetimeformatter formatter = datetimeformat.forpattern("yyyy/mm/dd hh:00:00");  datetime dt = new datetime();  string timestampasstring = dt.tostring(formatter);  string select = "select * " + tablename + " " + tablename + ".timestamp >= '"+ timestampasstring + "'";  pst = dbconnection.preparestatement(select);  pst.execute(); 

i'm using joda here can see, populate table in other point, format correct (yyyy/mm/dd hh:00:00). not sure if pass long directly query instead of converting string, not bother me right now.

since query condition >= "now" timestamp, unlikely returns something. need records within same day "now" timestamp. suppose have ask upper , lower bounds, i'm not sure how calculate lower boundary query...any ideas?

thanks!

i think need query

select * test1 ts >= current_date , ts < current_date + interval '1 day'; 

or

select * test1 ts >= now()::date , ts < now()::date + interval '1 day'; 

it's possible do

select * test1 ts::date = now()::date; 

but think perform worse because conversion of data in column.

sql fiddle demo


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -