If I want to take data for today from 00:00 until currently hour how can I do it ??? I have this table
datetime | hourly | clientchannel | servicename | service_count |
---|---|---|---|---|
13_02_2022 | 9 | ***** | notification | 2 |
Advertisement
Answer
Presuming that datetime
column’s datatype is DATE
(should be), then
select * from your_table where datetime between trunc(sysdate) and trunc(sysdate, 'hh24')
because
SQL> alter session set nls_date_format = 'dd.mm.yyyy hh24:mi:ss'; Session altered. SQL> select sysdate as right_now, 2 trunc(sysdate) as midnight, 3 trunc(sysdate, 'hh24') this_hour 4 from dual; RIGHT_NOW MIDNIGHT THIS_HOUR ------------------- ------------------- ------------------- 01.03.2022 08:01:20 01.03.2022 00:00:00 01.03.2022 08:00:00 SQL>
If datetime
‘s datatype is VARCHAR2
(bad choice), then you should first convert it to date, applying correct format model and hoping that there’s no garbage in that column:
where to_date(datetime, 'dd_mm_yyyy') between ...