Bauerhof
Bauerhof

Reputation: 165

get date records between today and beginning of the current week

suppose we have the table error_log, sth easily like:

+-------------+---------------+
| error_token | date_recorded |
+-------------+---------------+
| error_1     | 05.03.2017    |
+-------------+---------------+
| error_2     | 05.03.2017    |
+-------------+---------------+
| error_3     | 10.03.2017    |
+-------------+---------------+
| error_4     | 30.03.2017    |
+-------------+---------------+

what is the best way to get all errors that happened from the beginning of the current week till today.

and also the same if we want to get all errors between from the beginning of the current month till today.

Upvotes: 0

Views: 27

Answers (1)

Paul Maxwell
Paul Maxwell

Reputation: 35623

When you say "until today" I have assume that means up to, but not including, any part of today which is less than trunc(sysdate)

select *
from error_log
where date_recorded >= trunc(sysdate,'W') -- beginning of week
and date_recorder < trunc(sysdate) -- optional

select *
from error_log
where date_recorded >= trunc(sysdate,'MONTH') -- beginning of month
and date_recorder < trunc(sysdate) -- optional

see TRUNC

Upvotes: 1

Related Questions