Solved

Date Formatting Issue

Posted on 2013-06-18
4
388 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 24

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 24

Accepted Solution

by:
chaau earned 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

808 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