Oracle hint for the clueless of the day: date conversions

jdavidb on 2007-05-03T14:08:37

Example:

datevar2 := TO_DATE(TO_CHAR(datevar1, 'DD-Mon-YY HH24:MI:SS'), 'DD-Mon-YY HH24:MI:SS');

Hint: such conversions are never required. Hint 2: if you ever contemplate whether such a conversion is required, you probably don't belong in this business.

Hint 3: such conversions are not required even when date math is involved:

datevar2 := TO_DATE(TO_CHAR((datevar1 + 1/24), 'DD-Mon-YY HH24:MI:SS'), 'DD-Mon-YY HH24:MI:SS');

Taken from actual code, of course.

Oh, and hint 4: don't use such ugly date masks. Go with ISO standard or something: 'YYYY-MM-DD"T"HH24:MI:SS'. It's only internal anyway, right?