Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3331064
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:33:00+00:00 2026-05-17T23:33:00+00:00

I have a table1(DueDate varchar2(20)). It has thousands of date data in different format

  • 0

I have a table1(DueDate varchar2(20)). It has thousands of date data in different format with some bad data like characters.

eg.

YYYYMMDD,
MM/DD/YYYY,
MM-DD-YYYY,
M/D/YYYY,
'ABCD'
YYYYMMD,
YYYYMDD,

Now I had to get the dates that are past one week overdue. How do I do that?

Thank you for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:33:01+00:00Added an answer on May 17, 2026 at 11:33 pm

    This is one of the reasons that storing date information in a character field is such a bad idea.

    The easiest option is to create a function that attempts to convert the string to a date using the formats in whatever priority order you have (i.e. is 010203 Jan 2, 2003 or Feb 3, 2001 or something else) and catches the exceptions. Something like

    CREATE OR REPLACE FUNCTION my_to_date( p_str IN VARCHAR2 )
      RETURN DATE
    IS
      l_date DATE;
    BEGIN
      l_date := to_date( p_str, 'YYYYMMDD' );
      RETURN l_date;
    EXCEPTION
      WHEN others THEN
        BEGIN
          l_date := to_date( p_str, 'MM/DD/YYYY' );
          RETURN l_date;
        EXCEPTION 
          WHEN others
          THEN
            RETURN null;
        END;
    END;
    

    which works something like

    SQL> CREATE OR REPLACE FUNCTION my_to_date( p_str IN VARCHAR2 )
      2    RETURN DATE
      3  IS
      4    l_date DATE;
      5  BEGIN
      6    l_date := to_date( p_str, 'YYYYMMDD' );
      7    RETURN l_date;
      8  EXCEPTION
      9    WHEN others THEN
     10      BEGIN
     11        l_date := to_date( p_str, 'MM/DD/YYYY' );
     12        RETURN l_date;
     13      EXCEPTION
     14        WHEN others
     15        THEN
     16          RETURN null;
     17      END;
     18  END;
     19  /
    
    Function created.
    
    SQL> select my_to_date( '19000101' ) from dual;
    
    MY_TO_DAT
    ---------
    01-JAN-00
    
    SQL> ed
    Wrote file afiedt.buf
    
      1* select my_to_date( '01/02/2005' ) from dual
    SQL> /
    
    MY_TO_DAT
    ---------
    02-JAN-05
    

    Of course, you’d have to code the full set of valid date formats in your code, I’m just handling the first two in your list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tables i have Table1 user_id, date Table2 user_id, status I need something like UPDATE
I have two tables: table1, table2. Table1 has 10 columns, table2 has 2 columns.
I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many
I have 3 tables which contain different types of data related to each other.
I have two tables: table1 and table2. What would be the NSPredicate format equivalent
I have a data model where a 'Program' has a 1-to-many relationship with 'ToDo's
Ello, I am struggling with some date troubles here in PHP/MySql. I have a
I have Table1 and I need to get it to look like Table2: Table1
I have table1 which is being updated and inserted with data via sp's .
I have a JIRA environment which already has some information and i'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.