VB: Date format problem when loading *.csv - excel

i have problem with excel changing the date format so it fits regional settings.
my problem is:
i am creating tool in which user chose which *.csv file to import and work with. While tool is on user side i can't rely on regional setting - tool have to work for all.
Problem is that excel automatically change date format to fits regional setting and therefore it is wrong or i can't parse it with static delimiter (like '/').
I know the format in which the date is written in the csv file (yyyy-mm-dd or dd/mm/yy) and i would like to read that date as a text so i can use DateSerial to create correct date.
Is there any way to read csv only as text and prevent excel from changing it to date (based on user regional settings) automatically ?
Thank you.

When importing, specify the column as text.
Or, put an apostrophe at the start of each date value. This is the "this is a text value, don't reformat it" symbol.
example
123,'12/29/1999,blah blah

Related

Converting text to data Apr 06, 2020 in excel

I need help in converting this text value exported in text format from software management tool "Apr 06, 2020" to data format.
I have tried various methods like text to columns then picked all of the possible data formats but nothing works. Can you please help or suggest any solution?
Your problem is a mismatch between your Windows Regional Settings (which Excel relies on in order to parse your date), and the date format in the exported file (which appears to be US-English).
You have several choices:
If the file exported from your management tool is a text or csv file, you can probably use Power Query to import the file. Select Transform then right click on the Date column and select Change type => Using Locale => and select Date and English-US.
You could change your regional settings to English(united states) while you do the import, then change them back.
If none of the dates get converted, you could try this formula:
=DATE(RIGHT(A1,4),MATCH(LEFT(A1,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0), MID(A1,5,2))
Note that in the formula, you may need to change the commas to semicolons, or whatever your country uses to separate formula arguments
You can use below formula, Where A1 is date cell
=DATEVALUE(MID(A1,5,2)&"-"&LEFT(A1,3)&"-"&RIGHT(A1,4))

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)

Date format in CSV file strange behaviour

I have a .csv file that is created generated using some legacy software. There is no way to look inside the code at how or what its doing to produce the csv file.
My issue is that the date field format is behaving strangely.
The .csv file is storing the date in the following format.
MM-dd-yyyy HH:mm:ss.SSS
Looking in the file in notepad (raw data) we get a list of columns like this:
"01-12-2013 14:23:38.000",146.199997
"01-12-2013 23:20:29.000",146.199997
"01-13-2013 17:59:23.000",152.299988
"01-13-2013 18:08:40.000",147.300003
"01-13-2013 18:25:52.000",156.000000
"01-13-2013 18:35:14.000",146.300003
"01-13-2013 18:44:56.000",148.500000
"01-13-2013 18:56:41.000",151.699997
NOTE: I have stripped out the remaining columns to make it easier on the eye so we are only seeing the first 2 columns in the .csv file.
Now when I open this file in Excel 2010 version 14.0.6023.1000 (32-bit) I get date format problems.
Firstly if I just open the file I get blocks of mixed date formatting like this:
And this:
I can see that Excel is getting confused when the day value is switching from 12 to 13. If i then try to change the formatting to fix the issue using the following cell formatting settings:
Then I get the following displayed in the column when the day is less than 13:
And the following format when the day is greater than or equal to 13:
Any help would be really appreciated on this as I am now completely out of ideas.
NOTE: I have also tried copying the contents of the .csv file into another file but the same things occur in the new file.
This problem is to do with how Excel is interpreting the date format (M/D/Y vs. D/M/Y). It appears your system is setup for D/M/Y date formats. You won't find the setting in Excel because it derives it from your system settings. Go to the Language settings and add US English. Then set it to default and try opening the CSV file again.
Alternatively you can paste the csv file contents into a new sheet and use the 'Text-to-Columns' feature, which will let you specify the date format.
You have a conflict between the format of the .csv and your Regional settings.
First import the data as Text,(rather than double-clicking). Then in B1 or some other column enter:
=DATE(MID(A1,8,4),MID(A1,2,2),MID(A1,5,2))+TIMEVALUE(MID(A1,13,8))
and apply the desired formats:
I found a work around for my instance after reading the answers from #Gary's Student and #hughg. Thanks for the ideas.
So to fix my issue:
Modified my regional settings for dates and times to US.
Opened the file as normal in excel.
Selected the column in question and formatted cells into text. This converted all the dates in the file into floating point numbers.
Finally Apply following custom format to the cells: dd/mm/yyyy hh:mm:ss
The result is that every date in the file is now correctly formatted into UK date format.

Excel converts document exported from google keyword tool numbers into dates

When I import document from google keyword tool some curency values are converted to date for example 5.21 is converted to May 21. However there are some in the same column that are not conveted. What should I do that my document would not be disorted ? Tried to remove text proofing when typing, however I have document prewriten by google so it dosen't help.
Your regional settings seem to have the dot in the date format, with an order of MDY, so Excel will interpret a number like 5.21 as a date, but a number like 5.66 will remain a number.
Try exporting the Google output to a text file. Then open the text file with Excel via the File > Open menu. This will bring up the text import wizard. In Step 3 of the wizard you can select each column of data and specify what data type it contains, i.e. to tell Excel what each column contains.
You regional settings may also be set to have a comma as the decimal separator. In this case, Excel will not recognize 5.21 as a number at all. You can
change the Google output to produce numbers like 5,21 or
temporarily change your regional settings to use the format Google serves you
mark the column as text and import it as text, then use find and replace on that column to replace the decimal character with the one your system uses.

Libre Office 4.1.3.2: Import dates from text file, recognize right format

I am struggling with the different cell formatting types in Libre Office - I am aware of the manually adjustable Date formatting, but cant get Libre Office to recognise an input text string like:
" Wednesday, December 11, 2013   13:27"
where everything between the quotes is the cell content. Obviously I want the software to recognize, that this is a date and thus make a graph out of a large table, but using a manual formatter like:
" NNNN, MMMM D, YYYY HH:MM"
does not result in what I want, ie. the cell accepts my manual format but still cant cope with the content. What am I doing wrong? - any tips how I can nevertheless produce a graph with x-values with dates in this format? I dont want to awk around and manually convert these strings each time I have such a table...
Thanks a lot!
Be aware that during the import process you have a chance to set the date format during this import routine in Librecalc. Find this and use it.
I found that the fix must come while opening a CSV file to avoid being down the rabbit hole of errors and frustrations.
The preview of data on open is interactive. Who knew? :o
Do this:
Open
Select columns with dates in the preview
Change setting from Standard to Date in the dropdown

Resources