Error in converting varchar into dd/mm/yyyy

Hi all,
i need to insert the "date_of_birth" in 'dd/mm/yyyy'.
but in master table "date_of_birth" column is in Varchar2(15),and values in the master tables are not in proper format.
i.e) some values are like *'21-jan-1988'*,
and some are like *'01/21/1988'* and *'21-01-1988'*.
i need to insert into a new table in dd/mm/yyyy format.
thanks in advance.

You could use such a method, but WITH NOT GUARANTEE AT ALL_ that you're not inserting WRONG_ dates of birth.SQL> with rotten_data as (
  2  -- start of sample data --
  3  select '10-Jan-2010' vdate from dual
  4  union all select '10/Feb/2010' from dual
  5  union all select '10-03-2010' from dual
  6  union all select '10/04/2010' from dual
  7  union all select '17/04/2010' from dual
  8  union all select '11/14/2010' from dual
  9  union all select '23-04-2010' from dual
10  union all select '07-18-2010' from dual
11  union all select '01-02-2010' from dual
12  -- end of sample data --
13  )
14  select
15     vdate,
16     case
17             when regexp_like(r2,'^\D*$') then to_date(r1||r2||yr,'ddMonyyyy')
18             when regexp_like(r1,'^\D*$') then to_date(r2||r1||yr,'ddMonyyyy')
19             when (to_number(r1)>12 and to_number(r2)<=12) then to_date(r1||r2||yr,'ddmmyyyy')
20             when (to_number(r1)<=12 and to_number(r2)>12) then to_date(r2||r1||yr,'ddmmyyyy')
21             else to_date(r1||r2||yr,'ddmmyyyy')
22     end newdt
23  from (
24     select
25             vdate
26             ,regexp_substr(vdate,'[^-/]+',1,1) r1
27             ,regexp_substr(vdate,'[^-/]+',1,2) r2
28             ,regexp_substr(vdate,'[^-/]{4}',1,1)yr
29     from rotten_data
30  ) ;
VDATE       NEWDT
10-Jan-2010 10/01/2010 00:00:00
10/Feb/2010 10/02/2010 00:00:00
10-03-2010  10/03/2010 00:00:00
10/04/2010  10/04/2010 00:00:00
17/04/2010  17/04/2010 00:00:00
11/14/2010  14/11/2010 00:00:00
23-04-2010  23/04/2010 00:00:00
07-18-2010  18/07/2010 00:00:00
01-02-2010  01/02/2010 00:00:00
9 rows selected.This would still fail if the data is not one of those format +(or is not a valid date whatever the format)+ :
- dd/mm/yyyy
- mm/dd/yyyy
- dd-mm-yyyy
- mm-dd-yyyy
- dd-Mon-yyyy
- dd/Mon/yyyy
if one of the value is > 12 then it consider it as the day, the other one being the month.
If both are <=12, then it assumes the first is the day (dd).
Without any additionnal information, you cannot really make it better...

Similar Messages

  • Converting Varchar into Clob in Oracle 8i

    Hi All,
    Kindly tell me how can we convert a varchar variable into a Clob in Oracle 8i inside a stored procedure. I searched alot on the net, we have a To_Clob function available from 9i but doesn't exist in 8i. There was also talk about using dbms_lob, but i dont know how to use that to convert it.
    Kindly provide me with the details of how to do this as I am just starting out with Oracle.
    Thanks in Advance,
    Sajid.

    Hi,
    You can use the dbms_lob.to_clob() function(In oracle8i).
    In oracle 9i it is not required.
    Thanks & Regards
    venkata

  • How to convert date  into dd mon yyyy format

    hi all,
    i have a problem in date format i am using date like below .
    <%java.util.Date date = new java.util.Date();%>
    i am inserting date into a table and its storing like this
    insert into tablename (d_date) values (date)
    and its inserting date like below
    Sun Oct 19 09:05:45 GMT+03:00 2003
    i want to fetch date in dd mon yyyy format.
    with this format i want to make a select query.i struck with the format conversion.
    how to do this.
    any comments please.
    any help

    hi all,
    i understand now where i am wrong.
    the below code is not working why because in my server where i am executing code the regional setting month value is in arabic.
    i executed the same code in a different server where date and time jones are english its working fine.
    All the problem is in regional setting and not the jsp code.
    <%
    String whtEverDateFormatYouWAnt = "dd MMM yy";
    String str = new SimpleDateFormat(whtEverDateFormatYouWAnt).format(new SimpleDateFormat("EEE MMM dd HH:mm:ss vvv yyyy").parse("Sun Oct 19 09:05:45 GMT+03:00 2003"));
    out.print(str);
    %>
    Thanks a lot for the excellent solution.
    Thanks again.

  • Converting varchar to datetime 103

    Hi Guys
    Im making a select query where in a colomn the date is yyyy-mm-dd, i need dd-mm-yyyy (103). A simple convert query does not work because the colomn is not set as a datetime but as a varchar. Its not possible to change the tables at the source.
    The colomn name is DATE_IN
    I think the following post could be helpfull but i dont know how to fix the given statements into the select query
    http://stackoverflow.com/questions/1509977/convert-varchar-into-datetime-in-sql-server

    > in a colomn the date is yyyy-mm-dd, i need dd-mm-yyyy (103)
    As suggested above, this is string date format to string date format conversion, purely string operations.
    If you convert to DATE / DATETIME first (universal internal binary representation), then it may fail if invalid date. 
    You can use the ISDATE or TRY_CONVERT functions to check if the string date is valid.
    DATETIME functions:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • -3 error when converting music

    I keep getting a -3 error when converting m4a into another AAC/mp3
    Does anyone know what this is? Or why it is happening?
    It's using itunes10.6
    Thanks

    HI Scott,
    Perhaps something here might help: iTunes: How to convert a song to a different file format
    Carolyn

  • How can i convert this data(00000000) into date format(yyyy-MM-dd)

    Hi,
    i am using this method to convert date format from string.
    public static string FormatDate(string inputDate, string inputFormat)
                System.DateTime date = DateTime.ParseExact(inputDate, inputFormat, null);
                string datepresent = DateTime.Now.Date.ToString("yyyy-MM-dd");
                return datepresent;
    its working properly,
    but when input data is like 00000000 i am getting error this is not valid.
    how can i convert this into date format any help..!

    Have you tried the above code:
    I can see it is working with both Date and DateTime destination nodes.
    Map:
    Functoid Parameters:
    Functoid Script:
    public static string FormatDate(string inputDate, string inputFormat)
    string datepresent;
    if (inputDate == "00000000")
    datepresent = "0000-00-00";
    else
    System.DateTime date = DateTime.ParseExact(inputDate, inputFormat, null);
    datepresent = date.ToString("yyyy-MM-dd");
    return datepresent;
    Input:
    <ns0:InputDateString xmlns:ns0="http://DateFormat.SourceSchema">
    <DateString>00000000</DateString>
    </ns0:InputDateString>
    Output:
    <ns0:OutputDate xmlns:ns0="http://DateFormat.DestinationSchema">
    <Date>0000-00-00</Date>
    </ns0:OutputDate>
    If this answers your question please mark as answer. If this post is helpful, please vote as helpful.

  • Convert varchar(20) date to date that looks like mm/dd/yyyy

    Good afternoon,
    I am a total novice at SQL and have been tasked to change a varchar(20) date column (shows up as m/dd/yy) to show up as mm/dd/yyyy. I've looked at the previous posts, but being a novice, it's difficult to wade through the non-applicable stuff. The column
    that needs to be changed is field2, but I'm not sure how to construct a statement to reflect my objective.
    Thank you in advance. 

    The sample uses a table variable. You can program it the same way for a table:
    DECLARE @t TABLE (dt VARCHAR(20))
    INSERT INTO @t
    VALUES ('1/2/12')
    ,('3/10/10')
    ,('7/23/9')
    ,('aa')
    ,('12/31/99')
    ,('10/20/00')
    ,('10/20/01')
    SET DATEFORMAT mdy
    SELECT dt
    ,CONVERT(VARCHAR(10), CASE
    WHEN isdate(dt) = 0
    THEN NULL
    ELSE cast(dt AS DATE)
    END, 101) AS newDt
    FROM @t;/******** TRY_CONVERT() method ************/
    SELECT dt, newDt=CONVERT(varchar(10),TRY_CONVERT(date,dt),101) FROM @t;
    GO
    dt newDt
    1/2/12 01/02/2012
    3/10/10 03/10/2010
    7/23/9 07/23/2009
    aa NULL
    12/31/99 12/31/1999
    10/20/00 10/20/2000
    10/20/01 10/20/2001
    dt newDt
    1/2/12 01/02/2012
    3/10/10 03/10/2010
    7/23/9 07/23/2009
    aa NULL
    12/31/99 12/31/1999
    10/20/00 10/20/2000
    10/20/01 10/20/2001
    Starting with SQL Server 2012 you can use TRY_CONVERT().
    You can start studying datetime functions here:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    T-SQL Scripts at sqlusa.com
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • RFC Function Error: Cannot convert a value of 'MM/DD/YYYY' from type java.l

    hi experts,
    iam calling an RFC using SAP_JCO_Function. one of the input parameters is date which shud be in the format 'MM/DD/YYYY' but when i create a transaction property of data type DATETIME the format changes to " 2007-06-21 14:31:50 ". to refrain form passing this value at run time i have defined the transaction property as string and defaulted the value to MM/DD/YYYY.
    When i execute the RFC i get the error "Cannot convert a value of 'MM/DD/YYYY' from type java.l".
    Issue is with time field as well. Any suggestions would be appreciated.
    Thanks,
    Avinash

    Hi
    You can use datefromxmlformat( datetime, toformat ) .
    in toformat you give: "MM/dd/yyyy" and in datetime you pass your xml format date like: 2007-06-21 T14:31:50.
    Try like this. Hope this may help you.
    Thanks

  • How to convert JAVA.SQL.DATE date in YYYY/MM/DD format into DD/MM/YYYY

    i am using informix database which accepts date value in the form of DATE format......
    the other part of my application takes date from the field in DD/MM/YYYY format...so i have to convert my java.sql.date in YYYY/MM/DD fromat into DD/MM/YYYY fromat of same type before inserting into db......
    but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
    and also using format method can result only in string conversion........

    816399 wrote:
    i am using informix database which accepts date value in the form of DATE format......Huh?
    Maybe you mean Informix (fronted by JDBC) expects date values as java.sql.Date objects?
    the other part of my application takes date from the field in DD/MM/YYYY format...
    so i have to convert my java.sql.date in YYYY/MM/DD format into DD/MM/YYYY format of same type before inserting into db......I am not sure why you are talking about formats here.
    There is no formatting inherent in a java.util.Date object
    nor in a java.sql.Date object.
    but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
    and also using format method can result only in string conversion........You can easily create a java.sql.Date object from a java.util.Date object.
    String s = "31/12/2010";
    java.util.Date ud = new java.text.SimpleDateFormat("dd/MM/yyyy").parse(s);
    java.sql.Date sd = new java.sql.Date(ud.getTime());
    ud = sd; // java.sql.Date extends java.util.Date so no conversion is needed

  • Ive just subscribed online but realised I have the wrong service by mistake... I require Convert PDF into Word doc service but selected Adobe send in error, sorry. Can you please switch the service for me? Thanks Anthony Levy

    Ive just subscribed online but realised I have the wrong service by mistake... I require Convert PDF into Word doc service but selected Adobe send in error, sorry. Can you please switch the service for me? Thanks Anthony Levy

    Hi Tony,
    Please refer this KB document : Return, cancel, or exchange an Adobe order
    Please let me know if you need any further assistance.
    Regards,
    Rahul

  • Eliminating error during Convert from datetime to varchar

    I am using SQL 2008 R2.
    I am using this command:
    select Convert(varchar(12),Cast(out_date as datetime),101) From MyTable
    The output shows several rows of data and then returns an error:
    Conversion failed when converting date and/or time from character string.
    What is the syntax to eliminate errors from this select command?  Thanks
    MisterT99

    If it's a datetime, why you're converting it again to datetime?
    Why not
    select Convert(varchar(12),out_date,101) as NewDate, out_date From MyTable
    Should work just fine without extra step.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to convert system Date into DD-MMM-YYYY Format

    hi friends,
    please help me How to convert system Date into DD-MMM-YYYY Format.
    Regards
    Yogesh

    HI..
    data: w_dt(11) type c,
             w_month(2),
             w_mon(3).
    w_month = p_date+4(2). **p_date = given date**
    case w_month.
    when '01'.
    w_mon = 'Jan'.
    when '02'.
    w_mon = 'Feb'.
    when '03'.
    w_mon = 'Mar'.
    when '04'.
    w_mon = 'Apr'.
    when '05'.
    w_mon = 'May'.
    when '06'.
    w_mon = 'Jun'.
    when '07'.
    w_mon = 'Jul'.
    when '08'.
    w_mon = 'Aug'.
    when '09'.
    w_mon = 'Sep'.
    when '10'.
    w_mon = 'Oct'.
    when '11'.
    w_mon = 'Nov'.
    when '12'.
    w_mon = 'Dec'.
    endcase.
    Now...
      concatenate p_date6(2)  '-'  w_mon  '-'   p_date0(4)  into w_dt.
    write w_dt.

  • Getting 'Out of memory' error while opening the file. I have tried several versions of Adobe 7.0,9.0,X1. It is creating issue to convert PDF into TIFF. Please provide the solution ASAP

    Hello All,
    I am getting 'Out of memory' error while opening the file. I have tried several versions of Adobe 7.0,9.0,X1.
    Also, it is creating issue to convert PDF into TIFF. Please provide the solution ASAP.

    I am using Adobe reader XI. When i open PDF it gives "OUT of memory" error after scrolling PDF gives another alert "Insufficient data for an image". after clicking both alerts it loads full data of PDF. It is not happening with all PDFs. couple of PDFs are facing this issue. Because of this error my software is not able to print these PDFS into TIFF. My OS in window7*64. I tried it on win2012R2 and XP. Same issue is generating there.
    It has become critical issue for my production.

  • Converting PR into PO - error

    Hi, While converting PR into PO, (which is generated with PP02 control key in prod order and where there is no components to issue to vendor - only coating operation req from vender), the error message appears as "not possible to determine components- message no. ME154". How to crete PO in the above scenario? pls guide

    hi
    check for that purchase requisition any BOM is maintained for the material. if not maintain and do the PR.

  • How to convert varchar to date datatype while insert or update in table

    Hai All
    I need to convert to varchar to date.
    I have two Tables T1,T2
    T1 Structure
    Code varchar
    Time varchar
    Date varchar
    T2 Structure
    Empname var
    Empcode var
    Intime date
    Outtime date
    Intrin date
    Introut date
    Att_date
    Now i need to move Time form T1 to T2 Intime,outtime,intrin,introut according some condition
    So now i need to convert Varchar to Date while insert or update
    I have tried something
    Insert into T1 (code,intime,att_date)values
    (code,To_date(Date||time,'dd-mon-yyyy hh24mi'),att_date);
    OR While update
    Update T2 set Outtime=To_date(Date||time,'dd-mon-yyyy hh24mi') where...
    I got an error Ora-01861
    Regards
    Srikkanth.M

    You didn't show any example of your date or time values, butyou might need to add a space between them, like
    To_date(Date || ' ' || time,'dd-mon-yyyy hh24mi')

Maybe you are looking for

  • Text Vibrate; calls ring?

    Hi- Is there a way to get my phone to vibrate for incoming texts but still ring for incoming calls? I know I can silence texts, but can I make them vibrate? Thanks!

  • How to find the right kstat info & interpret it ?

    Having found out how to read the kstat structures I am still struggling with finding the right information which makes sense! I am interested in the following statistics: 0. Swap Space - similar to that reported by swap 1. Scan rate similar to that r

  • Connecting A100-306 & Desktop via Wireless Modem/Router: access is denied

    I am attempting to file/printer share between my A100-306 laptop and desktop units. I have used the Windows Wizard to create internet connection/LAN. This has been successful with the internet connection (via Belkin 54g Modem/Wireless Router) but my

  • When I import slides from iPhoto to iDVD, they lose color.

    I want to burn an iDVD from photos/movies that are on iPhoto.  Although they look fine in the work space, when I run the iDVD movie, about 75% of the slides lose all color or show only deep blues and purple.  I have already verified the color in sett

  • USMM: Database error reading table TUMRES

    Dear Experts, i want to make an export to LAW file with SAP program RSLAW_PLUGIN. In some of the systems the export (by downloading a file) works but in this ECC 6.0 the result is an error message: Database error reading table TUMRES Message no. BV10