SQL Developer: Load Data Date error - plsql

I am using Oracle SQL Developer 3.0.03. I am trying to upload an Excel file to an Oracle data table. I am getting an error for the date. The column in the database is a timestamp and I don't know what to put into the date format for the 'Data Load Wizard'. If I use the following format (dd-mom-yy hh.mi.ss), SQL Developer will show the following error:
--Insert failed for row 1 TIMESTAMP_COLUMN GDK-05047: A day of the month must be between 1 and the last day of the month.
--Row 1
INSERT INTO TABLE_1 (Column1, Column2, Column3, TIMESTAMP_COLUMN) VALUES ('Some Text','Some Text','Some more text',to_timestamp('40604.0', 'dd-mon-yy hh.mi.ss'));
The default number format IN EXCEL is: 40604.0
Which if you change the cell to a short date format you will get: 3/2/2011
I am trying to figure out what 'Format' I need to put into the FORMAT section of the 'DATA Load Wizard' that will accept the date format that is in EXCEL and upload it to Oracle as a TIMESTAMP.

I ran into the same thing today, and 'fixed' this two ways. The second way probably seems too complex, but it might help someone if they have a hard time automating the formatting of dates to look like Oracle's standard dd-mmm-yy.
Format the date columns in Excel as dd-mmm-yy and import directly into the table.
Highlight the column(s)
Choose "More Number Formats" where the existing format is (In Excel 2010, it says General in a dropbox on the Home tab
Select the last entry "Custom" in the Category box
Manually enter dd-mmm-yy in the Type: box
Format the date columns in Excel as mm/dd/yy, import the table in as text, write a manual insert statement from the temp text table using TO_DATE(date_field,'MM/DD/YYYY')
Highlight the column(s)
Choose "More Number Formats" where the existing format is (In Excel 2010, it says General in a dropbox on the Home tab
Select the "Date" entry in the Category box
Choose "03/14/01" from the list

The Excel "zero" date is January 0 (yes, zero), 1900. Since Oracle can't handle a "zero" day in a month you need to subtract 1 from the Excel value; thus the following should get you close to what you want:
SELECT CAST(TO_DATE('01-JAN-1900 00:00:00', 'DD-MON-YYYY HH24:MI:SS') AS TIMESTAMP) +
NUMTODSINTERVAL(41017.6361109954 - 1, 'DAY')
FROM DUAL
As far as "how to import it" goes, there's no Oracle date format that I'm aware of to do this. The easiest thing would be to import the value into a NUMBER column and then run a script to do the date conversion.
Share and enjoy.

yeah and that's the problem.
"A day of the month must be between 1 and the last day of the month."
1) how are these decimals created?
2) is this "04-06-2004" ? or are these seconds from 1970?
you need to add more detail about this number format!

Related

wordpress integer date to date

I have a wordpress sql database that records CREATE_DATE in an integer format
some examples are
1615776024
1615852620
1616024968
1616027330
1616981834
some of the entries were created this month, so the format in which the date is recorded doesn't reveal anything about itself.
I have tried these but all of these statements error
SELECT
CONVERT(DATE,CONVERT(CHAR(8),CREATE_DATE),112)
,CONVERT(DATE,CONVERT(VARCHAR(10), CREATE_DATE))
,CONVERT(DATETIME, CONVERT(VARCHAR(10), CREATE_DATE))
FROM WORDPRESS_TABLE
But they all error with the same error message :
Msg 241, Level 16, State 1, Line 1 Conversion failed when converting
date and/or time from character string.
can any one tell me how I can convert this into the following format please? dd/MM/yyyy in SQL?
Having thought about it a bit more, (like 10 seconds); I wonder if what you see is not epoch. I.e. number of seconds since Jan 1, 1970. In that case you can quite easily convert it back to a proper date by: SELECT DATEADD(S, [your-value], '1970-01-01').
Testing that on your first value in the original question: SELECT DATEADD(S, 1615776024, '1970-01-01'), gives me: 2021-03-15 02:40:24.000.
This should "square" up with what you said above regarding newly created entries this month.

Using a query with a datetime cell in spreadsheets

I need to query a cell that contains a datetime but its formatted by default when I import it to only show the date.
31/7/2020 19:18:58 (in reality it's like this)
31/7/2020 (but it shows this)
So when I run this query:
=QUERY(A5:R10, "select K")
It returns only the date no matter what I do:
31/07/2020
I've tried:
Options
Formatted like "yyyy-MM-dd HH:mm" it returns 00:00
Filter by datetime or timestamp
Used '"&Text(now(), "yyyy-mm-dd HH:mm"&"' or something like that
The question is:
Is there a way to do what I'm trying to do without reformatting the imported cells?
link to test it:
https://docs.google.com/spreadsheets/d/14rGPngGvFXGP8txMS2yFo1v4gPcI4K1oYWj_8yt2Uq8/edit?usp=sharing
when I select one cell with F2 it shows the time:
Thanks a lot for your time!
select column B and format it as date time
or without reformating it:
=ARRAYFORMULA(QUERY(1*(B2:B4&""), "format Col1 'yyyy-mm-dd hh:mm:ss'"))
or:
=ARRAYFORMULA(QUERY(TEXT(B2:B4, "yyy-mm-dd hh:mm:ss"), "select *"))
Just make sure your cells are formatted as Automatic
If not, even if you use the format clause of the query, the clause will be ignored

Date cleaning in excel,date values align to the left

I have excel file a date column, some of date are align to the right while others to the left.when i read the into r am getting this error.
Expecting date in A3547 / R3547C1: got '13/04/2018'
on dates align to the left. I have tried to clean the date in excel with no success,
You can do something similar to this
I have extracted the day, month and year from the string date using
some formulas
After that I have recreated the actual date from the
extracted day, month and year values
Formulas are as below
B2: =FIND("/",A2)
C2: =FIND("/",A2,1+FIND("/",A2))
D2: =LEFT(A2,B2-1)
E2: =MID(A2,B2+1,C2-B2-1)
F2: =RIGHT(A2,4)
G2: =DATE(F2,E2,D2)
Depending upon your actual data you may need to amend the formulas a little bit.
Please check whether all the cells in the column has date format and same date format.
Sometimes dates can be enter as text strings or other custom formats. Then there is a possibility to getting error like this.
This is how the data looks like in excel, both date and text
Load the same in MS Excel Power Query Editor, select the date column, Under the Transform Tab select "Split Column, By Delimiter", select "/" as the delimiter and Click OK. This separated the date into Month, Day and Year+Time.
Highlight the Day Column first, then Month, then Year+Time ...in that order, and then click "Merge Columns" under the Transform Tab.
Highlight the now Merged column and under "Data Type", select "Date/Time". You can now go back to the Home tab and Select Close & Load to get the cleaned data into Excel... as below;

Checking if a Date falls within a Range of Dates in SQLITE

I have an sqlite table with with 2 date columns (beginning & end). I am looking for a query that returns the date range a date falls in. e.g Checking range where 10-02-2016 falls given 2 records as follows
(01-02-2016 - 12-02-2016) & (13-02-2016 - 20-02-2016)
Clearly it falls in the first range but how do I do it in SQLITE. Please help?
I think the problem is next SQLite requires dates to be in format YYYY-MM-DD. With that format you could write a simple query:
select * from table where yourdate between begin and end
If you can't change your format you should look at next sqlite functions https://sqlite.org/lang_datefunc.html
Also you can try substr function to cotact date in needed format.

PHPExcel how to set date format in cell during export so filtration is available?

I would like to be able to filter my data like this:
Year ( + )
Month ( + )
Day ( + ).
At first i tought it's problem of cell formatting cause the format was set to General. So i did this:
$objPHPExcel->getActiveSheet()
->getStyle('G2:G256')
->getNumberFormat()
->setFormatCode(
PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2
);
And i worked. Now my cell G2 is formatted as date (at least excel says so). But i'm not able to sort this until i select cell and hit enter, after this ONLY this one cell is sortable. I have no idea why.
Thanks in advance for any help!
You need to set date values in cells as MS Excel timestamp values, not strings or unix timestamps.
Assuming from the way you're doing it at the moment that $row->user_created is a Unix timestamp value the, rather than
$formattedRow[] = date('Y-m-d',$row->user_created);
use
$formattedRow[] = PHPExcel_Shared_Date::PHPToExcel(
$row->user_created
);
which will set the value to a MS Excel serialized date/timestamp
You still want to set the number format mask, so that MS Excel knows how the date should be displayed; but as it's stored in Excel format rather than as a string, it will be sortable or filterable, or usable in formulae, etc

Resources