Problems changing date format of date as string - excel

I am currently trying to convert yyyymmdd type of date to a ddmmyyy format.
I've tried using DATE function and something like this:
=DATE(LEFT(A3;4);MID(A3;5;3);RIGHT(A3;7))
Original date for this function is 20120401 but the formula returns: 16.12.2104.
I've tried using functions YEAR, MONTH and DAY instead of LEFT, MID and RIGHT but that's not the right way.
I also tried using DATEVALUE but since Excel probably doesn't recognize yyyymmdd as a date, it gives me a #VALUE! error.
I've found a couple of solutions for SQL but it isn't my strong side yet - and this should be achievable easily in Excel.
Is there a way to do this in Excel?

Applying =DATE(LEFT(A3;4);MID(A3;5;3);RIGHT(A3;7)) to 20120401 in A3 is effectively to reassemble the component characters as below on the left:
These effectively become converted as on the right.
The solution was simply to exclude the digits highlighted red with:
=DATE(LEFT(A3;4);MID(A3;5;2);RIGHT(A3;2))
but the locale might have been a factor and when dealing with date serial numbers and/or what appears to be a date but is a string various other issues might have been involved.

Consider:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))

Related

How to standardize the text function in Excel?

=text(5/7/19,[Windows date format]) depends on the computer you are opening the Excel file from. For instance: =text(5/7/19, "mm/dd/yy") works on the company computer because that's how the windows formatted the date, but in my computer, it has to be =text(5/7/19, "dd/mm/yy") else it will return a different value and using other functions such as =datevalue(text(5/7/19, "mm/dd/yy") will return a #VALUE! error on my home computer. This is not good because it is very variable when the file is being moved around computers. How to standardize this?
So what about:
=TEXT(43592,"mm")&"/"&TEXT(43592,"dd")&"/"&TEXT(43592,"yy")
Or reference a cell where you have put your date.
Unfortunately I don't think it is possible - see the this link
Quote:
Problem: The value in the date_text argument is not in sync with the system’s date and time settings*
If your system date and time settings follow the mm/dd/yyyy format,
then a formula such as =DATEVALUE(“22/6/2000”) will result in a #VALUE! error. But the same formula will display the correct value when the system's date and time is set to dd/mm/yyyy format.
Solution: Make sure that your system’s date and time settings (both Short time and Long time) matches the date format in the
date_text argument.
I think the only solution is to make sure that your date is in the valid (i.e. recognised by the system) date format before any other function (like DATEVALUE) is applied.
It will be easy to achieve if your function is simply =text(5/7/19,[Windows date format]). You can reference your cell field (e.g. =[#Date]) and format a given cell using an "universal" date format (the ones that start with * sign).
However, if you are combining =text(5/7/19,[Windows date format]) with some other formula (e.g. when you want to display a full sentence like A very important event happened on 5/7/19) then, unfortunately, cell format won't save you here and we're out of solutions. In such case the end user would need to manually modify the date cell in order to make it recognisable.

Can't convert Date to Number

I have a userform and I take start and end dates from user as in dd.mm.yyyy format. To make it easier to compare dates, I want to turn it to a double or long type of value. I have tried as in below but it gives me an error of type mismatch.
endDate is already defined as Double and as you can see, Me.g_end.Value is string in proper format. Why do I get this error, and how can I handle it?
Also I need to add, DateValue(Me.g_end.Value) works fine with my friend to get value of date who uses Excel 2013. I use Excel 2016.
You need to enter dates in a valid format in order for Excel to recognize them as dates.
As far as I know, nowhere uses dots (periods) in dates. (As I recall, nowadays only one country in the world even recognizes dots as am official date separator.)
Click your Start menu and type Region to find and open Windows Region and Language Settings.
Note the format that your system is expecting for Short Date, including the symbol between each date part, and try entering your dates in Excel like that.

Excel: Text String to Date Conversion

I have a working formula for the following text to date conversion. However, I don't understand why the trailing 0 has to be added in order to show the year in YYYY format.
21.04.2016 converts to 4/21/2016
=(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))+0
It's very simple and straight-forward. However if you remove the 0 at the end of the formula, it will only show 16 instead of 2016. But I could do Right(A2,4) instead of Right(A2,2). But I still like to know why? Anyone? Thanks!
The trailing zero turns the whole thing into a math operation which causes the string (everything to the left of the +0) to be treated as a number.
you could also use *1 instead of +0
=(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))*1
or you could drop the +0 and at the front add -- before the ( and it should all do the same.
=--(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))
As Ed has correctly answered, this is because it is treating your date string as a number.
However, Excel has to interpret the string to get what number it really is, and to do this it relies on regional settings.
Under US regional settings, your formula works great, but when I plug it into excel with UK regional settings I get #Value because "04/21/16" isn't a valid date or number in the UK.
In order to avoid this problem, you should convert it to a date using the DATE() function, which will work irrespective of your regional settings.
=DATE(RIGHT(A2,4),MID(A2,4,2),LEFT(A2,2))

how to work with uneven dates in Excel?

I needed help as I am trouble with this recurring problem.
I have following date formats. American date format:
8/30/2013
11/1/2014
1/12/2014
For 8/30/2013 , I write =DATE(RIGHT(B2;4);LEFT(B2;1);MID(B2;3;2)), and I get it as "2013-08-30". For the other dates, I have to manually rewrite them again and again.
How can I write in one line to get 8/30/2013 or 10/12/2014 in a final date result like "2013-xx-xx?
if all entries are dates, you can use Text function:
=TEXT(B2, "yyy-mm-dd")
hope this helps.
Since you used string manipulation formulas and it worked for your first date, I believe that the date is actually text format.
As such, I would suggest using FIND to get the positions of / like this:
=DATE(RIGHT(B2;4);LEFT(B2;FIND("/";B2)-1);MID(B2;FIND("/";B2)+1;FIND("/";B2;FIND("/";B2)+1)-FIND("/";B2)-1))
It's quite long, I admit, but it's quite difficult to get substrings between two specific characters. If the year is always in that format, then you can use a slightly shorter formula:
=DATE(RIGHT(B2;4);LEFT(B2;FIND("/";B2)-1);MID(B2;FIND("/";B2)+1;LEN(B2)-5-FIND("/";B2)))

FIxing MS Excel date time format

A reporting service generates a csv file and certain columns (oddly enough) have mixed date/time format , some rows contain datetime expressed as m/d/y, others as d.m.y
When applying =TYPE() it will either return 1 or 2 (Excel will recognize either a text or a number (the Excel timestamp))
How can I convert any kind of wrong date-time format into a "normal" format that can be used and ensure some consistency of data?
I am thinking of 2 solutions at this moment :
i should somehow process the odd data with existing excel functions
i should ask the report to be generated correctly from the very beginning and avoid this hassle in the first place
Thanks
Certainly your second option is the way to go in the medium-to-long term. But if you need a solution now, and if you have access to a text editor that supports Perl-compatible regular expressions (like Notepad++, UltraEdit, EditPad Pro etc.), you can use the following regex:
(^|,)([0-9]+)/([0-9]+)/([0-9]+)(?=,|$)
to search for all dates in the format m/d/y, surrounded by commas (or at the start/end of the line).
Replace that with
\1\3.\2.\4
and you'll get the dates in the format d.m.y.
If you can't get the data changed then you may have to resort to another column that translates the dates: (assumes date you want to change is in A1)
=IF(ISERR(DATEVALUE(A1)),DATE(VALUE(RIGHT(A1,LEN(A1)-FIND(".",A1,4))),VALUE(MID(A1,FIND(".",A1)+1,2)),VALUE(LEFT(A1,FIND(".",A1)-1))),DATEVALUE(A1))
it tests to see if it can read the text as a date, if it fails, then it will chop up the string, and convert it to a date, else it will attempt to read the date directly. Either way, it should convert it to a date you can use

Resources