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.
sql oracle oracle11g
add a comment |
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.
sql oracle oracle11g
2
what is your expected output
– fa06
Nov 8 at 9:24
1
How is43238
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
add a comment |
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.
sql oracle oracle11g
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
sql oracle oracle11g
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 is43238
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
add a comment |
2
what is your expected output
– fa06
Nov 8 at 9:24
1
How is43238
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
add a comment |
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:
- In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).
- 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.
add a comment |
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
add a comment |
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
add a comment |
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:
- In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).
- 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.
add a comment |
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:
- In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).
- 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.
add a comment |
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:
- In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).
- 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.
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:
- In Excel, 1 Jan 1900 is saved as 1 (and not as 0 as an IT guy would expect).
- 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.
answered Nov 8 at 11:47
Codo
49.8k11110146
49.8k11110146
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 8 at 9:31
D-Shih
23.9k61331
23.9k61331
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 8 at 9:34
fa06
8,2821715
8,2821715
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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