Date Formats When Reading Excel with SSIS - excel

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);
}

Related

Python giving me datetime Value Error from CSV

I have one Python file that helps me pull and organize datetime data from a server into a pandas DataFrame, and then export out into a nice and usable CSV. My second Python script needs to read the CSV and analyze the data. If I do not touch the exported CSV, the analysis can read the CSV and runs smoothly. However, as soon as I try to merge a few CSV files together with Excel/other spreadsheet software, I get a datetime error
ValueError("time data %r does not match format %r" %
ValueError: time data '2019-12-26 23:00' does not match format '%Y-%m-%d %H:%M:%S'
Even though, it is a direct copy/paste and still saved as a CSV. Any guru can provide some insight on this matter?
Pretty sure this is an Excel issue, not a Python problem.
If you load a .csv that has timestamp strings into Excel, Excel recognizes the datetimes - and formats them. This format seems to default to MM.DD.YYYY hh:mm (the date component might be different depending on your locale):
If you save the file in Excel, the seconds are removed in the .csv!
The only procedure that seems to reliably prevent this behavior is to set a specific date/time format for the respective column, e.g. DD.MM.YYYY hh:mm:ss. AFAIK, You'll have to do this manually for each workbook
Or perhaps write a macro. In older Excel versions, I had a PERSONAL.XLSB for that; should still work with newer versions, you'll have to put it in C:\Users\[username]\AppData\Roaming\Microsoft\Excel\XLSTART
you can use .xlsx format instead of .csv, presumably you won't loose format information there
I see from the error that not all your CSV files have the same time format.
Some on them are in [hour:minute] and some in [hour:minute:second].
ValueError: time data '2019-12-26 23:00' does not match format '%Y-%m-%d %H:%M:%S'
Make sure that datetime fields in all of your CSV matched the same format.

Desired date format not saved when saving excel file as .CSV

having trouble with date formats in CSV file format(Excel)
I want the date in "YYYY-MM-DD hh:mm " format and I need it in .CSV format.
When reopening the file, the date format gets changed and it looks like "MM-DD-YYYY hh:mm".
Does anyboy know how I can retain my desired date format when saving the file as .CSV?
Thank you!
Use the format YYYYMMDD in all CSV files, which doesn't convert to date in Excel or you can do one of the below things
Use a Custom format, rather than one of the pre-selected Date formats, the export to CSV will keep your selected format. Otherwise it defaults back to the US format
Place an apostrophe in front of the date and it should export in the correct format. Just found it out for myself, I found this thread searching for an answer.
Change the date and time settings for your computer in the "short date" format under calendar settings. This will change the format for everything yyyy-mm-dd or however you want it to display; but remember it will look like that even for files saved on your computer.

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.

What date format can you use in CSV that Excel will recognize unambiguously?

Surely someone before me has needed to produce a year, month, day in a single field for a CSV that "just works" in popular versions of Microsoft Excel? I want only a date, no timestamp, though I suppose I could include 00:00 or something like that if I absolutely had to.
Panagiotis Kanavos points out that "Excel can only import it and try to guess whether the text values correspond to a certain type, using the user's locale settings." My question is about what format will cause Excel to guess correctly in the US and Europe, and ideally everywhere else.
If it's impossible or unreliable to do this in CSV, I will accept a link to using some zipped XML format or something that Excel and other spreadsheets accept universally instead of CSV.
This is NOT a duplicate of of the following:
Best timestamp format for CSV/Excel? because I want it without a timestamp.
What are the "standard unambiguous date" formats? because I need CSV specifically for Excel to read.
Excel CSV date format because I need Excel import from CSV, not export.
Read Date Format in PHP EXCEL because I need Microsoft Excel, not PHP Excel.
Excel will recognize YYYY-MM-DD as a global standard.
Cartoon from: https://www.xkcd.com/1179/
The difficulty with answering your question is that to test the proposed answer, the format must be tested in "all popular versions" of Excel
I have several versions of Excel and in my testing this:
worked in all my versions (English-US Locale)

SSRS TimeStamp incorrect format when exported to Excel

I have a datetimestamp field in SSRS, when I preview the report the data looks okay (2015-06-23 1:33:00 PM), but when I export the report to excel it creates ############### and not showing the date time. The dataset is done in SQL query cast(m.CallTime as datetime). What I want to happen is to display just the time in SSRS and Excel (1:30 PM). Thanks.
I've always had issues with the Excel export with date formats but I think that's more due to Excel propensity to guess wrong at the format I want. Why is it whenever I have a date with no time, it usually is formatted as time only (0:00)? Very annoying.
Make sure that your date is in a date format. You casted it in your query but you could also use CDATE to do it in SSRS.
Set the format using the Textbox's FORMAT Property to hh:mm tt .
It should come out as specified in Excel.

Resources