1

When running these statements:

select to_date('201103270100', 'YYYYMMDDHH24MI') from dual;
select to_date('201103270130', 'YYYYMMDDHH24MI') from dual;

I get these results:

27/3/2011 1:00:00
27/3/2011 1:30:00

which are correct.

But when running:

select to_date('201103270200', 'YYYYMMDDHH24MI') from dual

I get a wrong hour as result

27/3/2011 3:00:00

More samples:

select to_date('201103270215', 'YYYYMMDDHH24MI') from dual
select to_date('201103270245', 'YYYYMMDDHH24MI') from dual
select to_date('201103270300', 'YYYYMMDDHH24MI') from dual
select to_date('201103270330', 'YYYYMMDDHH24MI') from dual

27/3/2011 3:15:00
27/3/2011 3:45:00
27/3/2011 3:00:00
27/3/2011 3:30:00

When the date is 20110326, I get the correct result.

This is crazy... Is Oracle SQL bullying me with this conversion? Help is welcome!

Lalit Kumar B
  • 47,486
  • 13
  • 97
  • 124
davidbe
  • 840
  • 1
  • 6
  • 16

1 Answers1

2

Is Oracle SQL bullying me with this conversion?

Oracle is too dumb to bully a developer, unless the developer tries to bully it ;-)

There can't be different outputs without any reason. In Europe, in the year 2011, the day light saving was with effect from 27th March, 2011 at 2:00 AM. Source is wikipedia.

So, keeping in mind the day light saving, let's see the results for the datetime after 2:00 AM:

SQL> SELECT to_char(to_date('201103270100', 'YYYYMMDDHH24MI'), 'DD/MM/YYYY HH24:MI:SS') FROM dual;

TO_CHAR(TO_DATE('20
-------------------
27/03/2011 01:00:00

SQL> SELECT to_char(to_date('201103270130', 'YYYYMMDDHH24MI'), 'DD/MM/YYYY HH24:MI:SS') FROM dual;

TO_CHAR(TO_DATE('20
-------------------
27/03/2011 01:30:00

SQL> SELECT to_char(to_date('201103270200', 'YYYYMMDDHH24MI'), 'DD/MM/YYYY HH24:MI:SS') FROM dual;

TO_CHAR(TO_DATE('20
-------------------
27/03/2011 02:00:00

SQL> SELECT to_char(to_date('201103270215', 'YYYYMMDDHH24MI'), 'DD/MM/YYYY HH24:MI:SS') FROM dual;

TO_CHAR(TO_DATE('20
-------------------
27/03/2011 02:15:00

SQL> SELECT to_char(to_date('201103270245', 'YYYYMMDDHH24MI'), 'DD/MM/YYYY HH24:MI:SS') FROM dual;

TO_CHAR(TO_DATE('20
-------------------
27/03/2011 02:45:00

SQL> SELECT to_char(to_date('201103270300', 'YYYYMMDDHH24MI'), 'DD/MM/YYYY HH24:MI:SS') FROM dual;

TO_CHAR(TO_DATE('20
-------------------
27/03/2011 03:00:00

SQL> SELECT to_char(to_date('201103270330', 'YYYYMMDDHH24MI'), 'DD/MM/YYYY HH24:MI:SS') FROM dual;

TO_CHAR(TO_DATE('20
-------------------
27/03/2011 03:30:00

SQL>

If your provided data and examples are correct, then this should be the reason.

So, you should see the time portion exactly at 2:00 AM to shift to 3:00 AM. Similarly, 2:15 AM would be 3:15 AM. Just add an hour to the time for those which are after 2:00 AM.

Lalit Kumar B
  • 47,486
  • 13
  • 97
  • 124
  • Ugh - I've dug myself to deep into this problem to see clear. Thanks! Strange that our source system accepts this date/time... But that's another problem. – davidbe Apr 22 '15 at 07:04