Question

I have a problem with this sql:

select DATE_FIELD from table where
DATE_FIELD >= to_date(to_char(sysdate, 'yyyy/mm/dd'), 'yyyy/mm/dd')
and
DATE_FIELD <= to_date(to_char(sysdate, 'yyyy/mm/dd')+1, 'yyyy/mm/dd')

I would like to get the date from today 00:00:00 to tomorrow 00:00:00.

The DATE_FIELD field's DATA TYPE is DATE

In Tora/Toad works and in php not.

Error code:

PHP Warning:  oci_execute(): ORA-01722: invalid number
Was it helpful?

Solution

Your query:

select DATE_FIELD
from table
where DATE_FIELD >= to_date(to_char(sysdate, 'yyyy/mm/dd'), 'yyyy/mm/dd') and
      DATE_FIELD <= to_date(to_char(sysdate, 'yyyy/mm/dd')+1, 'yyyy/mm/dd')
----------------------------------------------------------^

I don't know what this would work anywhere, because to_char( . . . ) + 1 should fail. Well, I could imagine an arcane setting that would recognize the 'yyyy/mm/dd' date format and convert the string back to a date to add 1.

I would suggest the much simpler:

where DATE_FIELD >= trunc(sysdate) and DATE_FIELD < trunc(sysdate + 1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top