Solved

Date Formatting Issue

Posted on 2013-06-18
4
382 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
Comment Utility
Use to_date(:p_Enter_Date,'DD/MON/YY')

See here for all supported date formats
0
 

Author Comment

by:jose11au
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks so much, no more error.

Cheers
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now