From varchar to date format mm/dd/yyyy

Hi everyone,
I am pretty sure this question has been asked before, but I've been going through the blog for quite a while and can't seem to find anything!
Here is my problem. I am trying to compare a field in my database with a certain date, but the field is a varchar in the format mddyyyy, without comas or bars or anything, and I need to campare it with a date of the format mm/dd/yyy.
In Excel I used a quite complicated formula:
Right('0000000000' & [Maturity_Date],8) AS [New Mat #],
CDate(Left([New Mat #],2) & "/" & Mid([New Mat #],3,2) & "/" & Right([New Mat #],4)) AS [Mat Date],
But, to start with, Oracle doesn't seem to have the "right" operator.
Anyone could give me an idea.
Thanks for your time!! :)

Hi,
849073 wrote:
Hi!
Thank you very much, for your fast answer and your ideas!
Let me do this right then :) I'm using Oracle 9.2.0.8. Then you can't use REGEXP_REPLACE. Regular expressions were introduced in Oracle 10.
I didn't write the query beacuse it is mainly a bunch of joins I have already tested and they are right. I got the problem when inserting the date.
So, one of the problems is that the varchar might have only 1 digit for the month, so it would be like mddyyyy.
LPAD ( string_a
     , 8
     , '0'
     )will return a copy of string_a, with an extra '0' added at the beginning if it's only 7 characters long. That is
LPAD ('3312011', 8, '0')returns '03312011', which you can then use in any of the expressions I gave earlier, or in TO_DATE.
If string_a is already 8 characters long, e.g. '12312010', then the LPAD expression above returns it unchanged.
This is why the TODATE function will give back an error.
Then, as you correctly stated, I need to convert the string into a DATE type, since I need to check dates before a certain other or not. I am not sure if I made myself clear :SSorry, no. That's why you need to post some sample data, and the results you want from that data. In this case, the sample data would be just 2 columns (the string and the DATE), perhaps 6 rows and the results would be the rows where the one that is supposed to be earlier really is.

Similar Messages

  • How to convert the date format 'm/d/yyyy hh:mi:ss AM' to 'MM/DD/YYYY HH:M'

    How can i convert a the date format 'm/d/yyyy hh:mi:ss AM' to 'MM/DD/YYYY HH:MI:SS AM' in Oracle
    I have a query
    select UPPER(t.val_10) "TYPE", count(val_3) "Number of Transfers"
    from table1 t
    where t.is_active = 1
    and t.val_4 = 'INBOUND'
    and to_date(to_date(val_5,'MM/DD/YYYY HH:MI:SS AM'), 'DD/MM/YY') between to_date(to_date('01/08/2008 00:00:00','DD/MM/YYYY HH24:MI:SS'), 'DD/MM/YY') and add_months(to_date(to_date('01/08/2008 00:00:00','DD/MM/YYYY HH24:MI:SS'), 'DD/MM/YY'),1)
    group by UPPER(t.val_10)
    order by UPPER(t.val_10)
    I get the error [ORA-01861: literal does not match format string which i think is because
    val_5 has the values in the following format:
    8/29/2008 6:31:10 PM
    Does anyone have an answer?
    Thanks in advance
    Edited by: user2360027 on 26-Mar-2009 03:50                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    first off, you've got to_date(to_date(...)) - NEVER do this - you're forcing an implicit to_char which can cause all sorts of problems!
    What is the data type of your column val_5? If it's DATE then your query is simply:
    select UPPER(t.val_10) "TYPE",
           count(val_3) "Number of Transfers"
    from   table1 t
    where  t.is_active = 1
    and    t.val_4 = 'INBOUND'
    and    val_5 between to_date('01/08/2008','DD/MM/YYYY') and add_months(to_date('01/08/2008','DD/MM/YYYY') ,1)
    group by UPPER(t.val_10)
    order by UPPER(t.val_10)If it's a varchar2 (why, oh why, oh why, ...?!), then your query should be:
    select UPPER(t.val_10) "TYPE",
           count(val_3) "Number of Transfers"
    from   table1 t
    where  t.is_active = 1
    and    t.val_4 = 'INBOUND'
    and    to_date(val_5, 'mm/dd/yyyy hh:mi:ss AM') between to_date('01/08/2008','DD/MM/YYYY') and add_months(to_date('01/08/2008','DD/MM/YYYY') ,1)
    group by UPPER(t.val_10)
    order by UPPER(t.val_10)Remember that dates in DATE format are stored in an internal Oracle format - in order for you to tell Oracle that your string is a date, you need to use to_date. When you want to retrieve a date, you need to use to_char to put it into the format you want to see it in.
    Remember also that your nls_date_format defines the default format that you'll see a date, which is what is used in the implicit conversion that oracle does when you select a date:
    SQL> alter session set nls_date_format='dd/mm/yyyy hh24:mi:ss';
    Session altered.
    SQL> select sysdate from dual;
    SYSDATE
    26/03/2009 11:01:53
    1 row selected.
    SQL> alter session set nls_date_format='mm/dd/yy hh12:mi:ss AM';
    Session altered.
    SQL> select sysdate from dual;
    SYSDATE
    03/26/09 11:02:24 AM
    1 row selected.It doesn't make sense to convert something that's already in a DATE format into a DATE format - in order to do that, oracle has to first change the date into a string, and it does that by using the nls_date_format parameter setting - if you're working with dates-in-strings that are in a different format, then all sorts of problems arise, as you have found out!

  • Need regular expression for oracle date format 'DD-MON-YYYY'

    Hi,
    Can anybody tell me the regular expression to validate date in 'DD-MON-YYYY'.
    My concept is i have a table with just two columns item_name and item_date
    Both fields are varchar2 and i want to fetch those records from this table which have valid date format('DD-MON-YYYY').

    If it must be a regexp, this is a starter for you, note it carries the caveats mentioned by both posters above and in the linked thread
    mkr02@ORA11GMK> with data as (select '10-jan-2012' dt from dual
      2  union all select '10-111-2012' from dual
      3  union all select 'mm-jan-2012' from dual
      4  union all select '10-jan-12' from dual)
      5  select
      6  dt,
      7  case when regexp_like(dt,'[[:digit:]]{2}-[[:alpha:]]{3}-[[:digit:]]{4}','i') then 1 else 0 end chk
      8  from data
      9  /
    DT                 CHK
    10-jan-2012          1
    10-111-2012          0
    mm-jan-2012          0
    10-jan-12            0It will not validate content, only string format.
    And to emphasis the points made in the linked thread - dates in text columns is poor design. Always.

  • Problem with  date format "dd-MM-yyyy"

    hi all,
    i am using jdev 10.1.3.2
    My application ADF Swing app.
    in my database i have a table employee which contains "birthday".
    my problem is that i must use date format"dd-MM-yyyy".
    i added this format into "formatinfo.xml" file.
    than i choose it in my EO.
    i create a form which contains employees.
    for example i have an employee with a birthday=25-10-1970
    in my text field if user puts "1970-10-25"'which is not the best format) he will have a correct result "25-10-1970"
    but if user puts "25-10-1970" he will have as result "21-02-0031" which is not the real value.
    please help me.
    thanks.
    PS: i did some research before posting but i didn't find yet

    Rouz,
    Did you try what i said before?
    * Open you EntityObject
    * Expand the attribute tree
    * Choose your DOB attribute
    * Choose the Control hints pane on the right
    * Choose Formater: Simple date format
    * Choose Format mask dd-MM-yyyy
    Run your application and try it.
    This is how i change the format and it works perfectly.
    I uses the correct format to show the date and it enables me to edit the date using the format mask dd-MM-yyyy
    Edit: I just tried it myself. I can only reproduce it by removing my mask. Ergo, the application expects the default american format yyyy-MM-dd. By entering a date in the format dd-MM-yyyy the framework will convert it to yyyy-MM-dd and you'll end up with 0031-02-21.
    CONCLUSION follow the steps i discribed above to set your mask and you'll be fine.
    Message was edited by:
    Smolders Johan

  • How can i change the date format mm/dd/yyyy to dd/mm/yyyy

    How can i change the date format mm/dd/yyyy to dd/mm/yyyy

    Date, time and currency formats are controlled via Settings > General > International > Region Format - you can't just change the date format

  • How test the date formats  M/d/yyyy and MM/dd/yyyy .

    how test the date formats M/d/yyyy and MM/dd/yyyy .format should accept 3/3/1982 and 03/03/1982 dates.
    please help me

    georgemc wrote:
    kajbj wrote:
    Spoiler: Reply #3 is actually the answer to your question.Also, Bruce Willis is a ghost, the Titanic sinks and Verbal is Keyzer Soze.Only one of those endings really surprised me.
    You should've heard me in that theatre when the Titanic struck that iceberg...

  • How to set date formate dd/mm/yyyy from portal.

    Dear Experts,
    We are implementing ESS/MSS, my query is under ESS applications, date format is showing mm/dd/yyyy, then iam trying to change  user language is English (United Kingdom), from portal end, then its showing dd/mm/yyyy.
    My query is that is there any other way to change date format and how to set user language is English( united Kingdom) for mass users.
    Thanks in advance,
    Regards,
    Mahee.

    Hi,
    Iam trying to upload below format..for mass users....
    [User]
    UID=<employeeid>
    Password=init@123
    FIRST_NAME=xxx
    LAST_NAME=xxx
    group=xxxx
    Language=en_GB
    [User]
    by changing launguage = English (United Kingdom),Now I can able see the require format...dd/mm/yyyy.
    Thanks and Regards,
    Mahee.

  • Problem with date format dd/mm/yyyy. But I need to convert yyyy-mm-dd.

    Dear friends,
    I have the problem with date format. I receiving the date with the format dd/mm/yyyy. But I can upload to MySQL only in the format of yyyy-mm-dd.
    how should I handle this situation, for this I've created these code lines.But I have some problem with these line. please help me to solve this problem.
    String pattern = "yyyy-mm-dd";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    try {
    Date date = format.parse("2006-02-12");
    System.out.println(date);
    } catch (ParseException e) {
    e.printStackTrace();
    System.out.println(format.format(new Date()));
    this out put gives me Tue Apr 03 00:00:00 IST 2007
    But I need the date format in yyyy-mm-dd.
    regards,
    maza
    thanks in advance.

    Thanks Dear BalusC,
    I tried with this,
    rs.getString("DATA_SCAD1")// where the source from .xls files
    String pattern = "yyyy-MM-dd";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    try {
    Date date = format.parse("DATA_SCAD1");
    System.out.println(date);
    } catch (ParseException e) {
    e.printStackTrace();
    System.out.println(format.format(new Date()));
    this out put gives me Tue Apr 03 00:00:00 IST 2007
    But I want to display the date format in yyyy-mm-dd.
    regards,
    maza

  • URGENT !!!!   Problem with Date format MM/DD/YYYY in oracle database to BW

    Hi
    I am wondering if somebody can help me urgently.
    I have oracle database where date is of the format MM/DD/YYYY and I am loading data into BW. DATE data type
    Date in oracle database: 3/30/2007
    First when I used InfoObject ZDATE (with 0DATE) reference (DATS data type) data load failed saying that
    'Value '30-MAR-0 ' of characteristic 0DATE is not a number with 000008 spaces'
    Then I created ZDATE InfoObject as CHAR Type (Length 10) with PDATE Conversion Routine.
    when I created datasource using DB Connect and checked the contents using 'Display Table Contents' after creating data source the data field distorted as
    AR/-0/30-M
    After data load. when I checked PSA
    The Date records look same as AR/-0/30-M
    In cube the field appeared as  30-MAR-0  (last digit of year disappearing)
    In BEx report also it looks like 'AR/-0/30-M'
    Can somebody help me as quickly as possible.
    What should I do if i want to still use DATS data type for ZDATE?
    should I change date format in database if so to what?
    If I should use CHAR type with PDATE or any other routine can somebody give me the routine to have the date in the report exactly as it appears in database?
    I also tried changing date format in user profile...settings. But still its the same.
    Thanks in advance.

    Hello Snrella,
    You can solve this by converting the date format from oracle to the SAP internal date format  using an ABAP routine in the transfer rules.
    Assuming the oracle data field name is ZODATE then here's the ABAP you can use in the transfer rules. Create an ABAP routine transfer rule from ZODATE to your ZDATE infoobject, and then put this ABAP code there. (this code assumes that the format of the date from oracle is MM/DD/YYYY).
    concatenate tran_structure-/BIC/ZODATE+6(4) tran_structure-/BIC/ZODATE(2) tran_structure-/BIC/ZODATE+3(2) into result.
    Hope this helps.

  • Date format mm/dd/yyyy to mmddyyyy

    Hi All,
    I would like to convert the date fromat from mm/dd/yyyy to mmddyyyy.
    Actually i'm taking into a variable n checking it & concatenating it.
    But I want to know any fm for this.
    I want to know in which format the date is entering my program, if the date is coming in mmddyyyy, then I have no issues, I want to go n display in the same format.
    but if it is coming in the different i want it to b converted. mm/dd/yyyy to mmddyyyy.
    Can any body let me if there is any FM , and also let me know how to check the Date Format.
    Regards
    Rohini devi

    hi,
       WRITE : sy-datum.
       DATA : dat TYPE d.
       dat = sy-datum.
       WRITE :/ dat.
    the above mentioned code will give u output
    o/p=> 22/05/2008 -
    this is the format which u have
             22052008   -
    this is wat u wanted
    so jst assgin the variable which has value in dd/mm/yyy to a variable of type d
    reward points if useful

  • Adobe Forms Date Format DD.MM.YYYY.

    Hi Experts,
    I am new to Adobe Forms(Transaction SFP) . The Client has requirement to display the data in DD.MM.YYYY format.
    I saw that the standard 'Date fields' in ADOBE forms does not have this format.
    Any Ideas.
    Thanks.

    Hi
    Drag and drop the Date/Time Field  from Library pallet into Layout. Right click on it  -> Go to Palletes -> select Object -> go to the Field tab ->
    In Display Pattern you simply specify the date format as   DD.MM.YYYY and the active it and test it.
    Try this once. It will work.
    Thanks
    Sriiiiiiiii(Srikanth)

  • Date format  : mm/dd/yyyy HH12:MI:SS

    Hi,
    Wheteher the output of the 'mm/dd/yyyy HH12:MI:SS AM' only gives AM?
    Can we have PM in the date format like 'mm/dd/yyyy HH12:MI:SS PM'?
    When will we get the PM in the output while using the date format 'HH12:MI:SS'?

    Whenever you are in PM:
    sys@sid1> l
    1* select to_char(sysdate, 'MM/DD/YYYY HH12:MI:SS AM') from dual
    sys@sid1> /
    TO_CHAR(SYSDATE,'MM/DD
    07/09/2007 01:22:48 PM
    1 row selected.
    My time is 1:22:48 PM here. Even though I put AM in the to_char format, it noticed it was PM and changed it.

  • Search managed property date format dd/mm/yyyy instead of mm/dd/yyyy

    All regional settings in the site collections and the search site have been set to English(Australia), and the date format is correct within them however when I try to perform a search on a managed date property date:dd/mm/yyyy I do not get the expected
    results. I only get the correct results when searching date:mm/dd/yyyy.
    I found some articles regarding SP2010 and this issue, the correct answer was a link to a TechNet article with information about how to modify the XSLT in the results web part in the search centre. I could not find the XSLT in the results web part properties
    in SP2013 so I don't know if this information is redundant or if there is an easier way.
    It really seems like such a simple and common request so I can only imagine that its too obvious to blog about considering the time I've put into google on this one, and am I'm missing something here?
    Thanks,

    Hi karlostavitch,
    This issue seems to be caused by Query Language. Query Language is not the language of the Browser interface, but the language submitted to web sites. By default, the property of search results is null, the locale will be inferred from the browser language.
    You can change query language by exporting the Search web part, then adding query language property to the file.
    More information, please refer to the link:
    http://blog.orbitone.com/post/Language-sensitive-search-results-in-SharePoint
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Date Formats (dd/mm/yyyy and mm/dd/yyyy)

    Is there anyway to change the date format from mm/dd/yyyy to dd/mm/yyyy? I'm using XP and have changed all settings I can to UK from US but nothing changes. It's quite frustrating as I am used to the UK system.
    Thanks.

    georgemc wrote:
    kajbj wrote:
    Spoiler: Reply #3 is actually the answer to your question.Also, Bruce Willis is a ghost, the Titanic sinks and Verbal is Keyzer Soze.Only one of those endings really surprised me.
    You should've heard me in that theatre when the Titanic struck that iceberg...

  • Converting date format MM/DD/YYYY to DD/MM/YYYY in ISA B2B App

    Hi All,
    We have implemented CRM ISA 5.0 (B2B) application. Is it possible to change the date format to DD/MM/YYYY in ISA B2B web application. Now currently it is showing MM/DD/YYYY in all the pages. We need to change this format to DD/MM/YYYY, where and which the date shows the current format of MM/DD/YYYY. Is there any way in XCM settings to change the date format to achieve this. Do we require custom coding ?
    Kindly suggest us!!!
    Thanks and Regards,
    Saravanan

    Hi ,
    If the sol doesn't work with the system settings, do try passing the values in char format after concatenating appropriately adding "-".
    This ll work.
          date = '02252010'. "mmddyyyy"format
          concatenate date+2(2) '-'
                      date+0(2) '-'
                      date+4(4) into var.
    var-25-02-2010dd-mm-yyyy format.
    pass the variable 'var' to the webshop/web application.

Maybe you are looking for

  • Why is my site Title not showing in Firefox?

    Hello On my site at http://fbibiz.com/, the page Title flashes briefly in the Title bar, but then reverts to 'Mozilla Firefox'. The title tag is in place (correctly as far as I can see). Any suggestions, please, as to why my page Title is not showing

  • Hard disk failure and replacemen​t

    got hello, i own HP-G6-2005AX.My problem is that my hard disk is creating problem, the system does'nt boots up, when i contacted HP customer care, they told me to run hard disk dst test, the test took 3 hrs and gave result as failure. i am posting it

  • Installing SMC 3.5.1a on Solaris 10

    After "successfully" installing SMC via es-guiinst the process fails when attempting to use es-setup/es-guisetup. I get a message saying setup unsuccessful and pointing to a log (/var/opt/SUNWsymon/install/gui_setup_spinel.x) containg the following i

  • Change font size of reply button on discussion forum

    Hey, I am being requested to change the size of the reply button on one of our SharePoint discussion boards. They are needing it done for all current and new discussions that come up so that when someone clicks the reply that button is bigger. What i

  • HT1386 syncing iPhone to iTunes

    when i plug my device into my laptop it is not recognised on itunes, or as a device on my computer. and ideas on why this might be?