How to regularise Excel dates - excel

How can one regularise the dates format for below dates?
I want all below dates in format "22-Feb-17"
NOTE: Please note that I've tried converting the format by going to change format in the main menu section, but it didn't work.
Also tried: right click> Format Cell> Date > selected "22-Feb-17". This also didn't work.
27/04/2017
27/04/2017
27/04/2017
27/04/2017
5-Feb-17
5-Feb-17
5-Mar-17
5-Mar-17
5-Apr-17
5-Apr-17
5-Aug-17
5-Aug-17
22/5/2017
22/05/2017
24/05/2017
Please advise.

Go back to your original csv file, before it was ever opened and saved in Excel.
Then choose to Import the file (exactly where depends on your excel version). The Text import wizard will open and you will be able to specify the proper format of the dates in the csv file (eg. DMY).
Once they are properly imported as dates, you will be able to format the column however you wish.

Although it is definitely best to revert back to source and start again with an appropriate conversion, in case source is not available a formula conversion may serve:
=IF(ISTEXT(A1),DATE(2017,MID(A1,4,2),LEFT(A1,2)),DATE(2017,DAY(A1),MONTH(A1)))
This assumes (i) all dates are 2017 (easy enough to adjust if not) (ii) dates containing forward slashes are correct but in text format (iii) dates containing hyphens have the month and day switched around but are in date format.

Related

How to properly format dates in Google Sheets or Microsoft Excel

I have a spreadsheet I need to make in Google Sheets. The source of some of the data is exported to an Excel sheet. The data arrives in a dd/mm/yyyy format and I need to display it in a MON d format (Ex Sep 5).
The problem is both excel and sheets look at the date that arrives and think it is mm/dd/yyyy.
For example, 02/08/2022 is believed to be Febuary 8 even though it should be Aug 2. The problem then arises that neither of these platforms end up knowing how to convert this to Aug 2 and I end up having to do this manually.
Does anyone know how to get around this?
I have tried adjusting the format of the date, as well as using DateValue to convert (this fails since it understands the date as mm/dd/yyyy even when it is dd/mm/yyyy).
Any leads would be appreciated!
Thanks!
In Google Sheets, choose File > Settings > Locale and select a locale that uses the dd/mm/yyyy date format, before importing the data. You can then format the date column the way you prefer.
in gs:
=TEXT(REGEXREPLACE(A1&""; "(\d+)\/(\d+)\/(\d+)"; "$1/$1/$3"); "mmm d")
Try the following and format the result to your liking
=INDEX(IF(ISNUMBER(U2:U5),U2:U5,
IF(U2:U5=DATEVALUE("1899-12-30"),,
(MID(U2:U5,4,3)&LEFT(U2:U5,3)&RIGHT(U2:U5,4))*1)))
(Do adjust the formula according to your ranges and locale)
Functions used:
INDEX
IF
DATEVALUE
ISNUMBER
TRUNC
MID
LEFT
RIGHT
Well, for a formulaic solution, if the date is in A1, then the following places the correct date in B1:
=DATEVALUE(TEXT(A1,"DD/MM/YYYY"))
The TEXT function makes a string that will be the same form as your imported string out of the date produced during import. DATEVALUE then gives the proper date you desired.
The trick is in the TEXT step in which you reverse month and day in the string for DATEVALUE.
Naturally, instead of a helper column, it could just be wrapped around any reference to a date from column A, though one would have to remember to do so for all the years the spreadsheet is in use.
If you are importing, not just opening a .CSV file via File|Open and going from there, you have an opportunity to solve all your problems. You use the Ribbon menuing system's Data menu, select the very leftmost thing, Get Data and from the (no arguing THIS isn't a menu) menu that drops down, Legacy Wizards, then finally From Text (Legacy) which will open the old Excel Import Wizard. (You may notice this is very like the Data|Text to Columns Ribbon menu choice and that is because that choice is the old wizard minus the steps at the start that go looking to another file for the data because it knows, by law, that it has to already be in the spreadsheet... in other words, it looks the same because it IS the same.)
Then make selections for the first couple dialogs it presents you to get to the dialog in which you tell it to import columns as whatever: general (let Excel decide), text, date, and do not import. Choose Date and make the selection of DMY to import them properly as you desire them to be so you are never presented with the problem at all.
As you might guess, you can use the abbreviated wizard via the "Text to Columns" feature to do the same thing after import when you see they are reversed. Since it is a single column of data, the result will overwrite the original simplifying your work.
Why does this happen at all? Well, the "locale" folks have the idea. When Excel imports numbers that are in a form it recognizes could be a date, it looks to the operating system settings for the selected ways dates are understood. So if your operating system believes a date should be displayed "Month Day, Year" and Excel has a set of data it thinks fits that mold, it will convert them all using it. So you get those Feb 8's rather than Aug 2's.
Interestingly, it does two other things of note:
It looks at 8, count 'em, 8 rows of data to decide the data fits the pattern. Even with 1,000,000 rows to import, it looks at... 8.
Then it does them ALL as if God himself wrote the "8"... and dates like 25/03/2022 get imported as text not a real date, because they (oh, obviously) can't be dates... "25" can't be a month!
It IS possible to change settings (DEEP settings) to make Excel consider X number of rows in a data set before deciding such things. I found them here, on the internet, once upon a time, though I shouldn't like trying to find them again. It will consider up to a million rows in such an import, but... that'd make it pret-ty slow. And that's a million rows for EACH data column. I won't even say that "adds up" - I'll point out it "multiplies up."
Another technique is to add some number of starting rows to force the desired pattern onto the import. I've heard it works in TIME column imports so it ought to in DATE column imports but I've not verified such.
My bet is you will find the use of the "Text to Columns" feature of most use if you can use a hands-on approach - it does require literal action on your part, but is a fast operation. If you will see others using the spreadsheet though... well, you need a formulaic solution or a VBA one (macro with button for them to have some fun clicking as their reward for doing what they were trained to do instead of complaining to the boss you make bad spreadsheets). For a formulaic solution, the above formula is simple.
Last thought though: there's no error-checking and error-overcoming in it. So a date like "25/03/2022" in the data that imported as literal text is a problem. For handling the latter, an up-to-date approach could be:
=IF(TYPE(A1)=1,DATEVALUE(TEXT(A1,"dd/mm/yyyy")),DATE(INDEX(TEXTSPLIT(A1,"/"),1,3),INDEX(TEXTSPLIT(A1,"/"),1,2),INDEX(TEXTSPLIT(A1,"/"),1,1)))
in which the DATE(etc. portion handles finding text of the "25/03/2022" kind. Lots of less up-to-date ways to split the text Excel would have placed in the column, but since demonstrating what to do if it existed was the point, I took the easy way out. (Tried for a simple version but it wouldn't take INDEX(TEXTSPLIT(A1,"/"),1,{3,2,1}) from me for the input parameters to DATE.) TYPE will give a 1 if Excel imported a datum as a date (number), and a 2 if brought in as text. If empty or strange strings could exist, you'll need to deal with what those present you as well.

XLSX file saved as CSV leads to date format issues when we open the saved CSV file (XLSX "save as" CSV)

I am creating a CSV file from an XLSX FILE / CSV file meant for import into another application .... say Foxpro
I have tried my level best to convert Date in Column A with DD-MM-YYYY, using =TEXT(A1,"DD/MM/YY"), and all possible ways, However, if I save this to CSV Format and try to open the same, I find the first 12 days in DD-MM-YYYY ...(12-12-1965) form .....and the rest of it till 30th day, exactly the way I want it, like (12/13/1965..... and so on ...
Why do the first 12 days lead to a hyphenated date, instead of the "/" SLASH that I used in the =text() formula in Excel? subsequent dates (from the 13th day) are correctly displayed as 12/13/1965, 12/13/1965, and so on). When I try to import this CSV file into FoxPro, it leads to blank dates for the slashed dates viz., 12/14/1965, ... and so on...
I seek help to get rid of that Hyphens ... The formula bar CLEARLY displays the hyphen EVEN THOUGH THE VALUE IN THE CELL IS DISPLAYING "/" Slash... This causes import/data porting to lead to blanks as stated above... Unless the formula bar displays it as dd/mm/yyyy, I cant import it...
can someone help, please

How to format different DOB formats in Excel?

The image below shows different formats for DOB, what is the easiest way to format them to dd/mm/yyyy? The dates on the right are correct however the dates on the left are back to front and missing a 0 for all single numbers.
I would be willing to bet that 08/03/1997 was not originally 08-Mar-1997 but started out as 03-Aug-1997. Same goes for all of the other ambiguous DMY/MDY dates that Excel wrongly converted during the text import. Some dates remained as text because (as in A3) there are not 13 months in a year.
It makes no sense to convert the rest of the data now that half of it is already wrong. Abandon the import and then import it properly.
I could regurgitate the narrative from Excel VBA - Convert Text to Date but it has already been adequately described there. In short, bring the text back in with Data ► Get External Data ► From Text and specify the correct date conversion mask in the Text Import wizard. In VBA, use the Workbooks.OpenText method and specify the xlColumnDataType as MDY.

How to convert a date in Excel to ISO 8601 format

I am trying to save a date format in YYYY-MM-DD, for example, 2014-09-01 as a CSV file, but the format reverts back to the M/D/YYYY format when I do.
I tried converting the date as a string in Excel, but every time I open up the CSV file, it's back to the M/D/YYYY format. I need the ISO 8601 date format to be saved in a CSV file. How do I go about doing so?
The basic function is:
=TEXT(A1,"yyyy-mm-ddThh:MM:ss")
Use this to convert your Excel date columns to separate ISO 8601 date columns. Next, copy the ISO 8601 columns onto the originals (paste special: paste values only).
Delete the calculated ISO 8601 columns which now have garbage in them because Excel sucks at ISO 8601 dates.
You now have a transformed CSV or TSV or whatnot. Just save as the original format and ignore the stupid Excel whining about it not being its native file format and how you are going to "lose out" somehow by saving as CSV file and try not to think about the hours of your life Microsoft has stolen with that dumb dialog.
You can set up a cell, example :
Right click on cell > Cell format > Category > Custom > Type > write this :
aaaa-mm-jjThh:mm:ss (french format here)
yyyy-mm-ddThh:MM:ss (english format)
As a note of caution for non-English users. It just took me a while to figure out, that the format string is sensitive to your regional settings / locale. E.g. with my formatting settings to German:
=TEXT(C2;"jjjjMMtt")
(Although the OS and Excel are set to English.)
You could just jump straight to the nuclear option: Change your computer’s "Region and Language" settings to use the "yyyy-MM-dd" short date format.
I copied and pasted #Dirk Bester's formula above:
=TEXT(A1,”yyyy-mm-ddThh:MM:ss”)
but it wouldn't work, Excel 2010 complaining high and low. That is, until I changed the quote marks from some kind of "smart quote" to plain old ASCII 0x22 quote marks:
=TEXT(A1,"yyyy-mm-ddThh:MM:ss")
And now it works like a charm.
I believe you may well have created the right format in the .csv file.
But that Excel is automatically coercing that into a date value of the format you mention when you open the .csv file. A solution may be to import the .csv file rather than open it, and at step 3 of Get External Data, From Text, ensure that Text is selected for Column data format, where appropriate.
FWIW, none of the above worked for me in an Excel with 16th century dates, e.g. 26-08-1558 for the 26th of August 1558. So in order to convert that to an ISO date, I used:
=RIGHT(D2|4)&"-"&MID(D2|4|2)&"-"&LEFT(D2|2)
=DATEVALUE(LEFT(A1;10))
I used that

Some but not all Excel numbers show as a date

I have a big .xls file. Some numbers show as a date.
31.08 shows as 31.aug
31.13 shows as 31.13 (that is what i want all columns to be)
When I reformat 31.aug to number it shows as 40768,00
I have found no ways to convert 31.aug to 31.08 as a number. All I am able to do is to reformat 31.aug as d.mm and then it shows as 31.08 and when I try to reformat it from 31.08 to number it shows as 40768,00. No way to cheat Excel using different types of cell formats.
How's your regional settings? There are some Regions where the short date is identified by dd.mm.yyyy. (Estonian, for instance). Maybe if you change the regional settings for US / UK and paste the data again it won't be changed.
Worked in a small test I did here. Hope it helps.
Internally Excel stores Dates as integer. 1 is January 1. 1900. If you entered something that Excel interprets as a date then it will be converted into an integer. I think from this point on there is no way back.
There is an setting in Options on the tab "international" where you can define your decimal separator. If you set this to ".", then your Excel should accept 30.12 as decimal number and not as date.
As pointed out by others, Excel interprets some of your data as a date instead of a number, which depends on your regional settings. To avoid this happening try Tiago's and stema's responses, they will work depending on your regional settings.
To repair your problem in a large file after it has happened without re-entering/re-importing your data, you can use something like
=DAY(B5)+MONTH(B5)/100
to convert a "date" back to a number. Excel will still display it as a date when you first enter this, but when you reformat it as "Number" now it will display the value you originally entered.
Since your column seems to contain a mix between correct numbers and dates, you need to add an if() construct to separate the two cases. If you haven't changed the display format yet (i.e. it still displays 31.Aug) you can use
=IF(LEFT(CELL("format";B7);1)="D";DAY(B7)+MONTH(B7)/100;B7)
which checks if the format is a "D"ate format. If you have already changed the format to Number, but know all your correct data is below 40000, you can use
=IF(B5>40000;DAY(B5)+MONTH(B5)/100;B5)
As suggested above, go to Control Panel - Region and Language - Advanced Settings - Numbers - and change the Decimal Symbol from "," to "."
Good luck!
The data you are pasting, is it by any chance a pivot table.
For example, like you, I am copying a lot of data into a large spreadsheet. The data I am copying is from another sheet and it is a pivot table.
If I paste normally, half will show up as numbers, which they are in the source file and half will show up as dates, for no reason, which drives me insane.
If I Paste->Values however, they will all show up as numbers, and as I don't need the pivot functionality in the destination file this solution is fine.
All you have to do is format cell.
1-right click on the cell where you want to insert the number.
2-then click on Number and select 'General' from the number menu.
Hope this will help future people with the same issue.

Resources