regexp: how to deal with different date formats?

the date comes as varchar2 with '-'and':' as separators for day part and part time respectively. but it may come with different formats such as

1993-05-17
1993-05-17 13:04:23
1993-05-17 13:04
1993-05-17 13:4
1993-05-17 13:04
1993-05-17 13:4:2
1993-5-17-13:4:2
1993-5-7-13:4:2

and so on. date of final format should be ' YYYY-MM-DD HH24-SS'. is it possible to have an intelligent way to deal with different formats of date with separators above and convert the final using regexp format, so that it is compact and universal as possible with assumptions/examples above?

Thank you

As others have said, the smartest way is to keep your input in a format method and store your data in a date column.
But is a simple way to deal with this mess, without regexp,

with test as (
select '1993-05-17' d from dual
union all select '1993-05-17 13:04:23' from dual
union all select '1993-05-17 13:04' from dual
union all select '1993-05-17 13:4' from dual
union all select '1993-05-17 13:4:2' from dual
union all select '1993-5-17 13:4:2' from dual
union all select '1993-5-7 13:4:2' from dual
union all select '1993-05-17 1:4 PM' from dual
)
select d
     , to_date( translate( d, 'xampAMP', 'x' )
              , 'yyyy-mm-dd hh24:mi:ss'
              )
     + case when instr( upper( d ), 'P' ) > 0 then 0.5 else 0 end cd
from test

Tags: Database

Similar Questions

  • Receive error message when calculating the two fields with different date format

    I'm more familiar with SQL Server and Oracle, then after a search online without success, I ask here.

    I use developer PL/SQL with DB Oracle 11g Release 11.2.0.2.0 Enterprise 64-bit

    MyTable:

    ID_Number VarChar2

    Date of Date_Received

    Select ID_Number,

    Date_Received,

    To_Date (substr (ID_Number, 1.6), "YYMMDD") SentDate,.

    Date_Received - NumDays To_Date (substr (ID_Number, 1.6), "YYMMDD")

    FROM MyTable

    Where substr (ID_Number, 7.3) in ('ABC', 'ABD')

    and length (Trim (translate ((substr (ID_Number, 1,6)), '0123456789',' '))) a null value

    ID_Number Date_Received SentDate NumDays

    131002ABC1654106 10/16/10/2013-2013 14 2

    131004ABD8813899 4/12/2013-4/8/2013 4

    131014ABD1844832 10/16/10/14 OF 2013-2013 2

    Sometimes the first 6 characters in the ID_Number aren't the numbers and length (Trim (translate deletes records))

    I want just the records where NumDays > 2

    I tried to put the request in a subquery and using where NumDays > 2 outside.  I also tried using the calculation directly in the Where clause.  Without it in Where clause it works very well, with him in a place, I get the following error:

    ORA-01931: Date format picture ends before converting all of the input string


    I don't know how to put the two dates in the same format.  I tried to declare the format without result.  I don't understand how I can calculate in the selection, but do not use the same calculation in Where clause.

    Thank you for your help.

    Hello

    SQL is a language to describe the desired results.  How the system gets these results belongs to you don't have much say about which conditions will be applied when.

    One place where you can control the order of things is a CASE expression.  When you say

    CASE

    WHEN condition_1

    THEN expression_1

    END

    You can be sure that expression_1 will be evaluated only when cond_1 is set to TRUE.

    Try something like this:

    WITH got_sent_date AS

    (

    SELECT id_number, date_received

    CASE

    WHEN the TRANSLATION (SUBSTR (id_number, 1, 6)

    , 'x' 0123456789 '.

    , 'x'

    ) IS NULL

    THEN TO_DATE (SUBSTR (id_number, 1-6)

    , "YYMMDD".

    )

    END AS sent_date

    FROM MyTable

    WHERE (id_number, 7, 3) SUBSTR ("ABC", "ABD")

    )

    SELECT id_number

    date_received

    sent_date

    , date_received - sent_date AS num_days

    OF got_sent_date

    WHERE date_received > sent_date + 2

    ;

    If you would care to post some sample data (CREATE TABLE and INSERT statements) and the results desired from this data, I was able to test this.

    Of course, you'll still errors of execution if id_number starts with 6 digits, but they do not have to be valid, for example '131100' or '130229'.  This is one of the reasons why the date information storage in VARCHAR2 columns are a bad idea.  To work around this problem, see

    https://forums.Oracle.com/message/4255051

  • How to deal with the change in scope

    Dear,

    No org by enforcement period. Consolidation of the CDA. CDA entry.

    September, a company (X) is thrown into a perimeter (a-frame) and granted in a different consolidation perimeter (part B).

    I need perform the following acts:

    (A) CDA profit & loss of X, from September, must contribute to A scope results until December;

    (B) BAT profits/losses of X in September, October and December, must contribute to the results of scope B until December.

    (Operations under A) and B) can be automated? No idea how to do?

    I don't have a script. I need only a generic description on how you did.

    Thank you very much!

    According to my experience, assuming that you create a new entity for X under parent B, the best thing to do in these situations is to simply manage it via a journal entry.  You will write a day who would keep the CDA P & L (and in our cash flow of CDA case) result of X to the title of parent with equal and opposite impact hitting the new entity of X under B.  You post this journal in Sep, Oct, Nov and dec and continue loading data for a YEAR to X under B.

    However, if you simply drag & drop X under a new parent, I don't know how you deal with it.

    Kind regards
    Jason

  • Work with different raw formats?

    Is the workflow even when working with different raw formats in Adobe Camera RAW? OR did each file requires different steps or processes?

    Thank you.

    Do you mean, for example, NAVE against CR2?

    (Or, to use the vernacular style of the ESPN commentators, NAVE "verse" CR2.)  ;-)

    If so, there is no difference in how you work with them in Camera Raw. The differences are invisible to you, the user.

  • iCloud full - found two backups with different dates

    My 20g iCloud storage is full.  When I went to manage my data, there were 2 backups of my iPhone with different dates.  Can I remove 1 of them (the older one I guess) without affecting my current phone?  I guess that's when I upgraded my iPhone 4 to 5

    Of,.

    Yes, as long as you can identify with certainty the backup latest.

  • How to deal with analysis PC Performance & Stability Report

    Yesterday, when I just walked into my Office Xp, an error report in a program called... uh, PC Performance & Stability Report analysis, can possibly be, telling me to correct these errors have shown under its professional service.
    How to deal with him?
    Thank you for your advice it.

    Hello MeriClaybron,

    1. have you installed any show analyzing the program on your computer?

    This problem can be caused due to infection by the Virus. I suggest that you run a virus scan on your computer using Microsoft Safety scanner and check if you have the same problem.

    http://www.Microsoft.com/security/scanner/en-us/default.aspx

  • Apparently, my memory is almost full - no idea how to deal with not having a novice such am - sd card

    Apparently, my memory is almost full - no idea how to deal with not having a novice such am - sd card

    Hi sixty.

    It can also be a good idea to begin to transfer the content from your phone to a PC/Mac to help reduce the storage room.

    It is a process usually easy, just plug the unit to a PC, on the phone screen select MTP mode when it appears.

    Once finished, you just have to access the phone's internal memory and transfer pictures/videos from the DCIM folder.

    Let us know if you need help in this kind of task.

  • Error blackBerry software - synchronization failed, impossible to deal with organizing data

    I had a Q10 Blackberry last week.  I downloaded and installed the PC of Blackberry link 1.2.2.13 version.  Two-way sync USB worked fine.  Now, all of a sudden, I get the error message "synchronization failed, impossible to deal with organizing data."   I tried to reset the synchronization options, but not joy.  Also tried to uninstall and reinstall the software Link 1.2.2.13, once again no joy.  Any suggestions?

    UPDATE: I spent 4 hours on the phone and the remote session with the help of Blackberry last night.  After doing some troubleshooting to isolate the problem, determined that something on the device caused the problem of Outlook synchronization. One thing I've learned, it's that it can take a long time to synchronize and even though the progress of the screen may appear frozen, let it go until the end - sometimes it took 20-25 minutes, but eventually completed. Here's the process we went through - I would recommend appellant help BB and work with them to make sure you have not accidentally delete Outlook contacts and calendar of important information of your PC or BB device!.

    (1) we tried an uninstall/reinstall the PC Link BB software and that did not fix the problem.

    (2) to isolate the problem of synchronization.  We first did a synchronization of 2 channels 'contacts' and 'calendar' and who was a failure.  Then did a synchronization of only 2 channels 'contacts' and managed.  Then did a synchronization of only 2-way 'calendar' and that was a failure - so the problem was linked to calendar data and something on the device has been the cause of the problem or corrupted.

    (3) link BB allowing us to make a backup complete unit.

    4) then decided to do a 'Wipe security' on the device of BB Q10 to erase all the data and settings and return to a clean boot device configuration.  I was nervous about it - make double sure that Outlook all contacts and calendar data on the device and the PC are completely backed up in case something bad happens.  Nothing serious happened, but I was gald, we made the backup!

    (5) has the 'Security Wipe' feature (on the device, the settings > Security and privacy > wipe security) and phone rebooted without problems (takes a while to do).

    (6) then used link BB to do a sync test 1 channel 'contacts and calendar' from PC to device.  It worked without problem.

    (7) we then used BB link do a "restore" full backup of device, as we did in step 3 above.  It takes a while to make and was a success.

    (8) once the restoration of the aircraft was complete, BB link configured to perform a synchronization of 2 channels of the two 'contacts' and 'calendar '.  Does the synchronization and was a success.  Did a test by adding the new entry of the calendar on PC and did another 2-way sync - all worked very well.  Seems that the problem has been corrected, but will follow in the coming days.

    Lessons learned:

    (1) If you have a lot of Outlook contacts and calendar entries, the synchronization may take a long time.  Be patient and let it run - even if it seems stuck, etc!

    (2) save all Outlook data on the device and the PC to make sure that you have a backup something bad happened during troubleshooting.  We had not something bad happens, but I was gald we made a backup anyway.

    (2) call BB help - support person, I worked with was fabulous, even if it took some time to work through a patch.

     

  • How to deal with operating system windows 8.1 and apps on usb device

    Hi, I have a laptop Lenovo G505. Windows 8 64-bit was preinstalled in it. Later, I upgraded to 8.1. Laptop is almost 9 months and still under warranty. Since a few days, built Lenovo solution Center alert this analysis of hardware detected failures in one or more devices. On suggestion of Lenovo, I ran hdtune pro app in my machine and it also detected 3 hard drive errors. As my machine is under warranty, Lenovo is ready to replace my hard drive with a new one. But they say that it is the responsibility of the customer to return the windows 8.1 operating system and install in the new drive and their liability is limited to the replacement of the hard disk only. I am not computer savvy and I request concerned to guide me how to deal with operating system windows 8.1 on external media like USB, DVD, and install in the new drive. I also installed a number of apps and paid games. Therefore, I would like to resume these games also files so that I need not buy again. Assistance in this regard is required.

    Hello Mohan,

    Thanks for posting your query in Microsoft Community Forum.

    I can of course understand the situation and will be happy to help with your query.

    Let me ask you;

    • You have the key product for Windows 8 or 8.1?

    You can create an installation media (DVD/USB) for Windows 8.1 and re-install when you want. However, in order to create an installation media for Windows 8.1, you need the product key. If you don't have the product key for Windows 8.1, you can not create installation media.

    You can create the installation media for Windows 8 by using the product key Windows 8 If you have. In this case, install you Windows 8 first and then go to Windows 8.1 through store.

    As far as your paid apps (purchased by store) are concerned, you should be able to install them as soon as you sign in with the same Microsoft Account where apps were purchased.

    You can see the steps indicated by Ronnie Vernon replied on 24 December2013, re - install paid apps.

    You can follow the steps below to create installation media.

    1. Run the program Windows 8.1 configuration or installation of Windows 8 (depending on the availability of the product key for the specific operating system.
    2. When you are prompted to run or save the file, choose run

    3. When you are prompted to enter a product key, enter the 25-character product key, that you received when you purchased Windows 8.1 (or Windows 8).

    4. When you are prompted to install Windows 8.1 (or Windows 8), select install by creating media and then click Next.

    5. Select the type of media you want to use: either a Flash DRIVE or a DVD.

    To create a USB flash drive

    1. Click on the USB flash drive.

    2. Plug the USB key into a USB port on your PC.

    3. When you are prompted, select the USB key that you want to use, and then click Next.

      If you have files on the USB flash drive, it will remove them.

    To create a DVD

    1. Click on the ISO file , and then select the location where to save the ISO file.

    2. Insert a blank recordable DVD into your DVD drive.

    3. Burn the ISO of the DVD file using Windows disc Image burner, or another program DVD burning.

    Note: Ensure that the USB or DVD key that you use has nothing else stored on it and has a sufficient free space to download the Windows 8.1 Installer: about 2.3 GB for the 64-bit version.

    You can also read the article below to create a USB stick recovery.

    Create a recovery USB disk

    Hope this information is useful. Please feel free to answer in the case where you are facing in the future other problems with Windows.

    Thank you.

  • After the recent update on 06/01/2016, pdf files created on the Tamil language there are blank pages. How to deal with all this?

    After updated recent Acrobat reader, dated 06/01/2016, files already created with Tamil fonts show blank pages. How to deal with all this?

    Hi tnrk64,

    We just released Acrobat Reader for iOS version 15.4 on 23 January 2016.

    This version includes the special snag you have met.

    Would you please try it and let us know if it works for you?

    If you have problems with Acrobat Reader on the Apple App Store update, please take a look at the following page for advice: http://adobe.com/go/updatehelp

    Thank you!

  • How to deal with the table still growing?

    All tables are more and more applications. In some applications, tables become quickly more and more wide. How to deal with this problem?
    Currently I develop an application system. Should I add a large number of orders to remove the code for each table?

    The problem is delete is very time consuming.

  • How to set different date formats for different metadata fields?

    Hello

    Can I set different date for different fields of metadata formats? Standard Date format has a seconds. But I metadata fields, where I need to only show the date.

    I tried to use the rules and side effects. My code is: $xMyDate = formatDateOnly (xMyDate) $ >. But it does not work.

    Please how can I do?

    Thank you

    Martin

    Hi Laurent,.

    Large. This works. Good definition is:<$setValue("DOC_INFO","xDatumUkonceniRizeni",formatDateOnly(xDatumUkonceniRizeni))$>

    M.

  • How to deal with the JPEG image data

    I have a XML element defined by the user who provides a JPEG image.

    Is it possible to directly use this JPEG information in my PDF? (would be great - but seems to want)

    or I (seems more likley to me) should first write the JPEG data to a file and then load into my PDF file.

    If you can point me to a pretty good example of how to do this, however, it is accomplished, or can explain it in this forum

    I should be grateful if you would, and I think that others might be out a lot as well.

    Thank you

    See you soon

    For XFA-based PDF files, you can simply read the XFA specification to learn how to integrate the JPEG data in this grammar.  But it's easy enough...

  • Play with the date format TO_CHAR

    Hi all
    I'm learning how function TO_CHAR date format and code using the table double, but I had a few difficulties:
    SQL> select to_char(sysdate,'dl') test from dual;
    
    TEST
    -----------------------------
    Monday, December 20, 2010
    
    SQL> select to_char(sysdate) test from dual;
    
    TEST
    ---------
    20-DEC-10
    
    SQL> select sysdate test from dual;
    
    TEST
    ---------
    20-DEC-10
    
    SQL> select to_char('20-DEC-10','dl') test from dual;
    select to_char('20-DEC-10','dl') test from dual
                   *
    ERROR at line 1:
    ORA-01722: invalid number
    How can I place an explicit function TO_CHAR date?

    Best regards
    Valerie

    Valerie Debonair wrote:
    Hi all
    I'm learning how function TO_CHAR date format and code using the table double, but I had a few difficulties:

    SQL> select to_char('20-DEC-10','dl') test from dual;
    select to_char('20-DEC-10','dl') test from dual
    *
    ERROR at line 1:
    ORA-01722: invalid number
    

    How can I place an explicit function TO_CHAR date?

    Oracle converts implicitly your string to a date so that it can convert it to a string using your to_char function. Implicit conversion is based on your NLS_DATE_FORMAT settings, but you can never count on these implicit conversions.

    You can be...

    SQL> select to_char(to_date('20-DEC-10','DD-MON-RR'),'dl') from dual;
    
    TO_CHAR(TO_DATE('20-DEC-10'
    ---------------------------
    Monday 20 December 2010
    

    or

    SQL> select to_char(date '2010-12-20','dl') from dual;
    
    TO_CHAR(DATE'2010-12-20
    -----------------------
    Monday 20 December 2010
    

    Note that this one used Oracle fixed-date internal format YYYY-MM-DD, so if ever you use this method, you must specify the date string in this format. It also only deals with dates, not the component "hour".

  • How can I change the date format in Thunderbird for the list of received messages?

    Through 19/02/2015 12:28, I received my email with this format. Since that time, all the date Watch column is the time, the date does not show. How to get back to the default time and date format?

    The default is to show all the time on messages from today, with the date and time on all the other messages.

    http://KB.mozillazine.org/Date_display_format

Maybe you are looking for