how to convert excel serial date number to date in Oracle SQL











up vote
1
down vote

favorite












I was trying to covert same Excel date format to dd/mm/yyyy format. But I am not getting the correct result.




43236 16-May-18
43249 29-May-18
43238 18-May-18
43228 8-May-18
43238 18-May-18


I am using the below query




SELECT to_date('31-12-1899','dd-mm-yyyy')+43236 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43249 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43238 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43228 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43238 FROM dual;



I am getting the below result which is not correct




17-MAY-18
30-MAY-18
19-MAY-18
09-MAY-18
19-MAY-18


Please help me on that. I am using Oracle 11g R2.










share|improve this question




















  • 2




    what is your expected output
    – fa06
    Nov 8 at 9:24






  • 1




    How is 43238 supposed to return 18-May-18 and 20-May-18 at the same time (line 3 and 5)?
    – Codo
    Nov 8 at 9:39










  • Sorry for the confusion.. I have edited the post..
    – SwapnaSubham Das
    Nov 8 at 11:02















up vote
1
down vote

favorite












I was trying to covert same Excel date format to dd/mm/yyyy format. But I am not getting the correct result.




43236 16-May-18
43249 29-May-18
43238 18-May-18
43228 8-May-18
43238 18-May-18


I am using the below query




SELECT to_date('31-12-1899','dd-mm-yyyy')+43236 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43249 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43238 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43228 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43238 FROM dual;



I am getting the below result which is not correct




17-MAY-18
30-MAY-18
19-MAY-18
09-MAY-18
19-MAY-18


Please help me on that. I am using Oracle 11g R2.










share|improve this question




















  • 2




    what is your expected output
    – fa06
    Nov 8 at 9:24






  • 1




    How is 43238 supposed to return 18-May-18 and 20-May-18 at the same time (line 3 and 5)?
    – Codo
    Nov 8 at 9:39










  • Sorry for the confusion.. I have edited the post..
    – SwapnaSubham Das
    Nov 8 at 11:02













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I was trying to covert same Excel date format to dd/mm/yyyy format. But I am not getting the correct result.




43236 16-May-18
43249 29-May-18
43238 18-May-18
43228 8-May-18
43238 18-May-18


I am using the below query




SELECT to_date('31-12-1899','dd-mm-yyyy')+43236 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43249 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43238 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43228 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43238 FROM dual;



I am getting the below result which is not correct




17-MAY-18
30-MAY-18
19-MAY-18
09-MAY-18
19-MAY-18


Please help me on that. I am using Oracle 11g R2.










share|improve this question















I was trying to covert same Excel date format to dd/mm/yyyy format. But I am not getting the correct result.




43236 16-May-18
43249 29-May-18
43238 18-May-18
43228 8-May-18
43238 18-May-18


I am using the below query




SELECT to_date('31-12-1899','dd-mm-yyyy')+43236 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43249 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43238 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43228 FROM dual
UNION ALL
SELECT to_date('31-12-1899','dd-mm-yyyy')+43238 FROM dual;



I am getting the below result which is not correct




17-MAY-18
30-MAY-18
19-MAY-18
09-MAY-18
19-MAY-18


Please help me on that. I am using Oracle 11g R2.







sql oracle oracle11g






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 11:01

























asked Nov 8 at 9:22









SwapnaSubham Das

1189




1189








  • 2




    what is your expected output
    – fa06
    Nov 8 at 9:24






  • 1




    How is 43238 supposed to return 18-May-18 and 20-May-18 at the same time (line 3 and 5)?
    – Codo
    Nov 8 at 9:39










  • Sorry for the confusion.. I have edited the post..
    – SwapnaSubham Das
    Nov 8 at 11:02














  • 2




    what is your expected output
    – fa06
    Nov 8 at 9:24






  • 1




    How is 43238 supposed to return 18-May-18 and 20-May-18 at the same time (line 3 and 5)?
    – Codo
    Nov 8 at 9:39










  • Sorry for the confusion.. I have edited the post..
    – SwapnaSubham Das
    Nov 8 at 11:02








2




2




what is your expected output
– fa06
Nov 8 at 9:24




what is your expected output
– fa06
Nov 8 at 9:24




1




1




How is 43238 supposed to return 18-May-18 and 20-May-18 at the same time (line 3 and 5)?
– Codo
Nov 8 at 9:39




How is 43238 supposed to return 18-May-18 and 20-May-18 at the same time (line 3 and 5)?
– Codo
Nov 8 at 9:39












Sorry for the confusion.. I have edited the post..
– SwapnaSubham Das
Nov 8 at 11:02




Sorry for the confusion.. I have edited the post..
– SwapnaSubham Das
Nov 8 at 11:02












3 Answers
3






active

oldest

votes

















up vote
1
down vote













You're simply off by 1. Use 30 Dec 1899 (instead of 31 Dec 1899) as the reference date for index 0.



SELECT to_date('31-12-1899','dd-mm-yyyy') + 43236 FROM dual


The reason it's 30 Dec 1899 and not 1 Jan 1900 is twofold:




  1. In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).

  2. Excel treats the year 1900 has a leap year even though it wasn't. Therefore, Excel also has a number for 29 Feb 1900, which did not exist.






share|improve this answer




























    up vote
    0
    down vote













    If I understand correctly you can try to use TO_DATE and set language culture then TO_CHAR for your expected format.



    select TO_CHAR(TO_DATE('16-May-18','DD-Mon-YY', 'nls_date_language = american'),'DD/mm/yyyy')
    from dual


    or like this.



    SELECT TO_CHAR(to_date('31-12-1899','dd-mm-yyyy')+43236,'DD/mm/yyyy') FROM dual


    sqlfiddle






    share|improve this answer




























      up vote
      0
      down vote













      You can try below using to_char() function



      select to_char(TO_date('31-12-1899', 'dd-mm-yyyy')+43236,'DD/MM/YYYY')  from dual





      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204725%2fhow-to-convert-excel-serial-date-number-to-date-in-oracle-sql%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote













        You're simply off by 1. Use 30 Dec 1899 (instead of 31 Dec 1899) as the reference date for index 0.



        SELECT to_date('31-12-1899','dd-mm-yyyy') + 43236 FROM dual


        The reason it's 30 Dec 1899 and not 1 Jan 1900 is twofold:




        1. In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).

        2. Excel treats the year 1900 has a leap year even though it wasn't. Therefore, Excel also has a number for 29 Feb 1900, which did not exist.






        share|improve this answer

























          up vote
          1
          down vote













          You're simply off by 1. Use 30 Dec 1899 (instead of 31 Dec 1899) as the reference date for index 0.



          SELECT to_date('31-12-1899','dd-mm-yyyy') + 43236 FROM dual


          The reason it's 30 Dec 1899 and not 1 Jan 1900 is twofold:




          1. In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).

          2. Excel treats the year 1900 has a leap year even though it wasn't. Therefore, Excel also has a number for 29 Feb 1900, which did not exist.






          share|improve this answer























            up vote
            1
            down vote










            up vote
            1
            down vote









            You're simply off by 1. Use 30 Dec 1899 (instead of 31 Dec 1899) as the reference date for index 0.



            SELECT to_date('31-12-1899','dd-mm-yyyy') + 43236 FROM dual


            The reason it's 30 Dec 1899 and not 1 Jan 1900 is twofold:




            1. In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).

            2. Excel treats the year 1900 has a leap year even though it wasn't. Therefore, Excel also has a number for 29 Feb 1900, which did not exist.






            share|improve this answer












            You're simply off by 1. Use 30 Dec 1899 (instead of 31 Dec 1899) as the reference date for index 0.



            SELECT to_date('31-12-1899','dd-mm-yyyy') + 43236 FROM dual


            The reason it's 30 Dec 1899 and not 1 Jan 1900 is twofold:




            1. In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).

            2. Excel treats the year 1900 has a leap year even though it wasn't. Therefore, Excel also has a number for 29 Feb 1900, which did not exist.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 8 at 11:47









            Codo

            49.8k11110146




            49.8k11110146
























                up vote
                0
                down vote













                If I understand correctly you can try to use TO_DATE and set language culture then TO_CHAR for your expected format.



                select TO_CHAR(TO_DATE('16-May-18','DD-Mon-YY', 'nls_date_language = american'),'DD/mm/yyyy')
                from dual


                or like this.



                SELECT TO_CHAR(to_date('31-12-1899','dd-mm-yyyy')+43236,'DD/mm/yyyy') FROM dual


                sqlfiddle






                share|improve this answer

























                  up vote
                  0
                  down vote













                  If I understand correctly you can try to use TO_DATE and set language culture then TO_CHAR for your expected format.



                  select TO_CHAR(TO_DATE('16-May-18','DD-Mon-YY', 'nls_date_language = american'),'DD/mm/yyyy')
                  from dual


                  or like this.



                  SELECT TO_CHAR(to_date('31-12-1899','dd-mm-yyyy')+43236,'DD/mm/yyyy') FROM dual


                  sqlfiddle






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    If I understand correctly you can try to use TO_DATE and set language culture then TO_CHAR for your expected format.



                    select TO_CHAR(TO_DATE('16-May-18','DD-Mon-YY', 'nls_date_language = american'),'DD/mm/yyyy')
                    from dual


                    or like this.



                    SELECT TO_CHAR(to_date('31-12-1899','dd-mm-yyyy')+43236,'DD/mm/yyyy') FROM dual


                    sqlfiddle






                    share|improve this answer












                    If I understand correctly you can try to use TO_DATE and set language culture then TO_CHAR for your expected format.



                    select TO_CHAR(TO_DATE('16-May-18','DD-Mon-YY', 'nls_date_language = american'),'DD/mm/yyyy')
                    from dual


                    or like this.



                    SELECT TO_CHAR(to_date('31-12-1899','dd-mm-yyyy')+43236,'DD/mm/yyyy') FROM dual


                    sqlfiddle







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 8 at 9:31









                    D-Shih

                    23.9k61331




                    23.9k61331






















                        up vote
                        0
                        down vote













                        You can try below using to_char() function



                        select to_char(TO_date('31-12-1899', 'dd-mm-yyyy')+43236,'DD/MM/YYYY')  from dual





                        share|improve this answer

























                          up vote
                          0
                          down vote













                          You can try below using to_char() function



                          select to_char(TO_date('31-12-1899', 'dd-mm-yyyy')+43236,'DD/MM/YYYY')  from dual





                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            You can try below using to_char() function



                            select to_char(TO_date('31-12-1899', 'dd-mm-yyyy')+43236,'DD/MM/YYYY')  from dual





                            share|improve this answer












                            You can try below using to_char() function



                            select to_char(TO_date('31-12-1899', 'dd-mm-yyyy')+43236,'DD/MM/YYYY')  from dual






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 8 at 9:34









                            fa06

                            8,2821715




                            8,2821715






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204725%2fhow-to-convert-excel-serial-date-number-to-date-in-oracle-sql%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Schultheiß

                                Verwaltungsgliederung Dänemarks

                                Liste der Kulturdenkmale in Wilsdruff