Problem, reading date field from visual foxpro dbf file - excel

when I try to get data from dbf file to Excel PowerQuery, using Visual Foxpro OLE DB provider all is ok except date field - I get 1899-12-30. The same result when I try to do that with C# + OLEDB.
When I just open this dbf file with Excel, instead of date string I see symbols like that:Ü|%
How to read/convert dbf date field correctly?

Actually, the Dec 20, 1899 is basically an empty date is intentional. Going WAYY WAYYYY back, I can't remember the exact time I needed, but that was like a baseline date within Excel. When trying to read in dates from Excel, I would have to add the number of days between date() and date(1899,12,30) to get correct date. It should not be considered a garbage value.

The problem was non standard dbf date field format - instead of 8 bytes it takes 4 bytes only (after analyzing with hex viewer). So, Visual FoxPro OLE DB provider could not interpret it correctly.

Related

Date Formats When Reading Excel with SSIS

experts!
I've got two similar Excel files (xlsm) as templates. Both have sheets with Date column.
Visible format for both files when use Excel is "10-Aug-20".
But when I read these files with SSIS process with Script Component Source using Microsoft.ACE.OLEDB.12.0 with "IMEX=1"... ta-da... some I see as expected, but some are 10.08.2020 00:00:00
This causes me a lot of pain because I will process files from both US (MM/dd/yyyy) and German (dd.MM.yyyy) date formats and would like to have locale-independent date format to process dates same way.
How can I force excel to give or ssis to read a correct date format.
Any suggestion how to see both files same programmaticly is most wanted and highly appreciated!
You could try to use the script component (as Transformation) to transform the data by using DateTime.TryParseExact
string dateString = "10-Aug-20";
string format = "dd-MMM-yy";
DateTime dateTime;
if (DateTime.TryParseExact(dateString, format, "en-US",DateTimeStyles.None, out dateTime))//if (DateTime.TryParseExact(dateString, format, "de-DE",DateTimeStyles.None, out dateTime))
{
Console.WriteLine(dateTime);
}

Oracle SQL DB import to Excel issues with date formats

I have a excel file that automatically imports data from an Oracle DB into the sheet. Everything works fine, but date formatting is wrong. In the Oracle DB, the format is 01-JAN-2016. But when it exports to Excel, the format suddenly changes to 1/1/2016.
Is there a good solution to this? Setting the cell format beforehand doesn't work. Once the data is imported, Excel automatically switches format to Date. I have tried a lot but can not solve this issue so I am wondering if any of you have ideas as to what to do. Thanks.
The date isn't stored in "01-JAN-2016" format, that's just a representation of the underlying date value.
The recordset contains the data, not its representation. Format the column with a NumberFormat like dd-mmm-yyyy, and 2016/01/01 will look like 01-JAN-2016.

SQL Developer Export Encoding for Excel Date

Regarding datetime values, is there an encoding that I can select from
SQL Developer that when I export to Excel it is formatted as datetime?.
I tried UTF-8 & UTF8. What appeared was,
01/01/85 12:00:00.000000000 AM
This isn't filterable from the filter drop down in excel.
In Microsoft's SSMS, I could select ANSI and the datetimes values would appear fine.
But SQL Developer doesn't seem to have this option (ANSI).
Current work around that I do is to extract in Excel the value into another column with the date formulas (date, year, month, day).
Edit
Exporting as datetime that excel can interpret, oracle can actually do it as well.
But it must be exported as csv.
It is the same for Microsoft's SSMS.
The oracle excel export that I was using had results that were in 1 sheet and the sql executed in the another.
No, we don't format the cells when we create the Excel file. You'll need to do that in Excel when you open it.

Reading MS Excel file from SQL Server 2005

I need to read a Microsoft Excel 2003 file (.xls) from a query in SQL Server 2005, and then insert some of that data into some tables. Reading the file and then using its data is not a problem in itself, but I found that, for a column, sometimes I get a NULL value instead of the value that's shown in the Excel file. To be more specific: This column is always just one character long, and it can contain any one digit from 0-9, or the letter 'K'. It's when the column contains 'K' that the query gives me a NULL value. My assumption is that, since the first few rows contain numbers as the values of this column, the query assumes they will always be numbers, and when it finds a letter it just turns it into NULL.
I tried changing the format of the cells in the Excel file to text, and using CAST and CONVERT (not at the same time) on the value to try to make it a varchar, but it does nothing.
That looks like an older OLE DB driver for Excel. Not that it doesn't work--you can still "query" the spreadsheet with it. Maybe try something newer:
SELECT * FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml;HDR=YES;Database=C:\File.xls',
'SELECT * FROM [Sheet1$]')
You'll need an updated ODBC driver on the SQL Server (make sure to get the appropriate 32 vs 64 bit version).

SSIS not importing TEXT column from Excel correctly (integer results in NULL value)

I have Excel 2003 files which are imported through SSIS into SQL 2008 R2. With one of the columns I hit a big problem. The column is defined as TEXT in the Excel sheet. Out of 36 rows 32 are having values like XTZ23, they get import correctly. The last 4 rows however
are just numbers like 2646672. They are imported as NULL. If I change the connection String to IMEX=1 and modify the registry to TypeGuessRow=0 these numbers end up like 2.64667e+006.
What did I miss here?
I know this is an old post, but for future searchers, just add IMEX=1 into the connectionstring of your Excel manager in the SSIS.
First solution would be to change excel column format if possible.
Second, I have had this problem 2 years ago, excel file couldn't be changed since I was getting it from another service ... I can`t remmember correctly but I have called custom code/function or it was some sort of transformation inside SSIS that was converting specific column rows from one data type to another.

Resources