Senthil RS Senthil RS -4 years ago 114
SQL Question

db2 between timestamp query

i am new to DB2 can you please help how to execute query in db2 for between timestamp with AM and PM format.

Below is the table

ID NAME TIMESTAMP
== ==== =========
6 Xavier 02/02/2016 2:24:32 AM
7 Paul 02/02/2016 2:46:53 PM
8 Adam 02/02/2016 4:05:39 PM
9 Newton 12/02/2016 5:29:46 PM
10 Jack 14/02/2016 9:29:46 PM


I want to use the above table to select names on 02/02/2016 between 1AM to 4PM

Can you please help to achieve.

Answer Source

Assuming the datatype for timestamp is date , use

select * From your_table where timestamp between
to_date('02/02/2016 01:00:00','DD/MM/YYYY HH24:MI:SS')
and 
to_date('02/02/2016 16:00:00','DD/MM/YYYY HH24:MI:SS')

You might be seeing 'AM' / 'PM' due to your client settings.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download