Patan
Patan

Reputation: 17893

SQL does not fetch today's transaction when using trunc

I am trying to get all rowsprior to current time and date including today's transactions.

select * from mytable 
where joindate <= trunc(sysdate)

I did not get rows that belong to today.

AM I doing any thing wrong.

Upvotes: 0

Views: 66

Answers (1)

tjati
tjati

Reputation: 6089

Try to run

select trunc(sysdate) from dual;

and you will see an output like 2014-05-24 00:00:00. trunc sets the time to midnight.

You can try

where joindate < trunc(sysdate)+1

to look for all joindates before 2014-05-25 00:00:00 which should meet your requirements.

Upvotes: 2

Related Questions