Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date Formatting Issue

Posted on 2013-06-18
4
Medium Priority
?
397 Views
Last Modified: 2013-06-18
Hi All,

I need your assistance.

I have the below code in a query but I get the an error due to date formatting.

Can anyone please help?


case
when to_date(:p_Enter_Date,'DD/MMM/YY') - MAX(st.sales_date)   > 180 –180 days
then 'Y'
else 'N'
END                                                               as Late_Sales_Payment


ORA-01821: date format not recognized
01821. 00000 -  "date format not recognized"
0
Comment
Question by:jose11au
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:chaau
ID: 39258399
Use to_date(:p_Enter_Date,'DD/MON/YY')

See here for all supported date formats
0
 

Author Comment

by:jose11au
ID: 39258423
Hi All,

I forgot to explain what I am trying to archive in above case statement

If :p_Enter_Date- MAX(fx.entry_date) > 180 days then 'Y' else 'N'

Thanks
0
 
LVL 25

Accepted Solution

by:
chaau earned 2000 total points
ID: 39258436
You should be fine with your statement (I guess " - 180 days" was just a comment). Just fix the format.

case
when to_date(:p_Enter_Date,'DD/MON/YY') - MAX(st.sales_date)   > 180
then 'Y'
else 'N'
END                                                               as Late_Sales_Payment

Open in new window


BTW, "MON" format is for abbreviated month name, like Jan, Feb,  Mar, etc.
If your p_Enter_Date takes another format (i.e dd/mm/yyyy) you need to use 'DD/MM/YYYY'.

BTW, did you know, that format mask part of this function is optional. You could just use to_date(:p_Enter_Date) and let Oracle to figure out what the user has entered. It is not a bulletproof option, but it will work for any fancy format users may come up with
0
 

Author Comment

by:jose11au
ID: 39258447
Thanks so much, no more error.

Cheers
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question