2

I wrote following simple select query to fetch data, which is greater than the particular given date.

select *
from   XVIIX.emp_tasks
where  TASK_START_DATE > to_Date('30-MAR-18','DD-MM-YYYY');

But the result is not what is expected from that.

enter image description here

Can someone explain me what is the root cause for this behavior?

Aravinda Meewalaarachchi
  • 2,551
  • 1
  • 27
  • 24

2 Answers2

3

I think the problem is converting two digit years to four-digit years. It is better to use explicit date literals:

where task_start_date > date '2018-03-30'
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
3

There are two problems with the format model of to_Date('30-MAR-18','DD-MM-YYYY');

The month is expressed as a 3 character month, but the format model for month is MM, which expects a month number, MON is for an abbreviated month name.

YYYY is expecting a 4 digit year, you have supplied two, either supply 4, or change the format model to YY

Andrew
  • 26,629
  • 5
  • 63
  • 86