|
|
| Re: SUM CASE date difference calculation [message #639179 is a reply to message #639176] |
Thu, 02 July 2015 10:27   |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
bowgieman wrote on Thu, 02 July 2015 20:53
[code]
date_out>'30-Apr-2015'
'30-Apr-2015' is NOT a DATE, it is a STRING. Use TO_DATE to explicitly convert a literal into date, and make sure you use proper format model and NLS_DATE_LANGUAGE.
|
|
|
|
|
|
|
|
| Re: SUM CASE date difference calculation [message #639187 is a reply to message #639183] |
Thu, 02 July 2015 10:44   |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
bowgieman wrote on Thu, 02 July 2015 21:09Thanks for your help Lalit,
I now get the error ORA-01830: date format picture ends before converting entire input string. What should the NLS_DATE_LANGUAGE be?
SUM(CASE WHEN date_out>'30-Apr-2015' or date_out is null
THEN (to_date('30-Apr-2015','J')-date_in)
ELSE round((date_out-date_in)+1) END) AS days
You still have a string instead of date.
HINT : The comparison condition
P.S. : To know more about NLS_DATE_LANGUAGE, please read the documentation on DATATYPE first. And make sure you pay more heed for DATE datatype. You know what, "Apr" is not the same month name for someone who isn't using NLS_DATE_LANGUAGE as AMERICAN(Just an example).
Edit : Silly typo
[Updated on: Thu, 02 July 2015 10:46] Report message to a moderator
|
|
|
|
|
|
| Re: SUM CASE date difference calculation [message #639192 is a reply to message #639187] |
Thu, 02 July 2015 10:50   |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
If you are only concerned with the date and not any other element, then I suggest you to use the ANSI date literal.
From the docs,
Quote:The ANSI date literal contains no time portion, and must be specified in exactly this format ('YYYY-MM-DD')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|