Comparing dates coming from different files in Excel - excel

I am trying to link two Excel files and compare the values from first one in the second one, but I have a problem at some point.
So the date 28/07/2021 comes from the other file (which is call 3WLA). I had to use the function TEXT(..., "dd/mm/yyyy") otherwise it displays 44405 which is an other form of the date. Now I want to compare this date with other ones but it doesn't work as showed in the pictures below.
The picture shows the comparison of two dates coming from the other excel file 3WLA (still using the function TEXT(..., "dd/mm/yyyy")). We clearly see that there is a problem as it should display TRUE. In the same way, when I compare a date from 3WLA (i.e. using TEXT(..., "dd/mm/yyyy")) with a date random in my file it give me the following
where 28/07/2021 is given by = TEXT('[3WLA.xlsx]Block-First-Fix'!$AM$1,"dd/mm/yyyy") and 29/07/2021 by = 29/07/2021

chris neilsen already gave you the answer in the comments.
To clarify further: The text "29/07/2021" and the date formatted to look like "29/07/2021" are different data types. To help with this MS Excel automatically formats numbers and dates to be aligned to the right and normal text to be aligned to the left
In B1 you can see that the date has been formatted in the same way as per the formula in A2, but since the output in B2 is of the text data type, the two are not considered the same.
You can use the formula DATEVALUE to convert from text to date serial number. (Read more about date serial numbers here).
If your texts with dates are too different from your local settings date formats, DATEVALUE might not give you correct results. In that case use DATE function in combination with some text functions such as LEFT, MID, RIGHT
You can format the cell to make the date more readable using either the number formatting field or the dropdown from the ribbon

Related

Doing calculations in excel with Datetime format including milliseconds

I have this column in excel. The format is dd/mm/yyyy hh:mm:ss.SSS where SSS is milliseconds.
How can I make calculations such as subtracting two cells from each other? I keep getting an incorrect format error but I cannot find a format that includes date and time with milliseconds.
I am able to change the notation of the DateTime value but not split it into two cells.
Comments up above will suggest the built in test to columns method which works really well. Scotts tip about the third step is imperative. Jeroen's comments is using the DATEVALUE function which can be picky and somewhat dependent on your system settings. There is a third choice of using DATE. Jeroen's formula already does most of the work but needs a little tweaking. The nice part of DATE is it is not picky nor reliant on system settings.
Important tidbit of info. Excel stores dates as an integer with 1 representing 1900/01/01. Time is stored as a decimal which represents percentage of a day. So 0.5 is 12:00 noon. Also 24:00 is not a valid time for excel but will still work with some functions.
The DATE function looks for 3 arguments to be passed to it. Year, month, and day in that order. So it is just a matter of pulling the applicable parts of your timestamp as a string out and placing them in the right location. There is a Similar function for TIME.
Let assume one of your timestamps is located in C3
in D3 you can place the following formula to convert the date from text to an excel date:
=DATE(MID(C3,7,4),MID(C3,4,2),LEFT(C3,2))
In E3 you can place the following formula to convert the time from text to an excel time:
=TIME(MID(C3,12,2),MID(C3,15,2),MID(C4,18,6)
To get the information together its simply D3+E3. however if you want to place the whole formula in one cell and avoide helper columns, the formula would look like:
=DATE(MID(C3,7,4),MID(C3,4,2),LEFT(C3,2))+TIME(MID(C3,12,2),MID(C3,15,2),MID(C4,18,6)
Now that the time in in excel format you can perform operations on it, apply formatting to make it look like you want, and use various excel functions with it.

Formula losing date formatting

I have been using the following as a formula array beginning in column R2 for an Excel spreadsheet that combines the data from four columns:
=L2&" "&N2&" "&Q2&" "&P2
Column L contains the date in the following format: 2/23/2015.
The formula used to show the date as shown above, but now for some reason the format has changed to go from 2/23/2015 to 42081.
I can't seem to get date to show as it once did. Also the Excel spreadsheet I apply this to is downloaded from a different source each day so I don't know if default formatting has changed even though the data is exactly the same.
When you concatenate like that you just get the values not the formatting because number formatting doesn't apply in the text string created. You can use TEXT function to dictate the format in this context, e.g.
=TEXT(L2,"m/d/yyyy")&" "&N2&" "&Q2&" "&P2
With MDY convention, if L2 is formatted as Text prior to entry then keying in 2/23/2015 would preserve that display in a formula that concatenates it with other strings. Similarly if not keyed but entered with Ctrl+:.
If L2 is formatted as General or Short Date the date index will be concatenated (42081 in the example above) though the display in L2 will not change.
While a change in formatting may be the most likely explanation (and a solution provided by #barry) another possibility is a change in the date convention from DMY. In which case 2/23/2015 would have displayed and concatenated as that even in a cell formatted as Short Date. 2/12/2015 in that case however would have displayed as such but in the 1900 date system concatenated as 42340 - the date serial number for December 2, not February 12.

Importing CSV into Excel

I am simply importing CSV into Excel, In which I have a date column. it seem like this.
10.22.2014 13:34:00
When I am finish Importing Now I want to convet the whole date column to look like this in the format cell section but it is not working for me. Can you suggest another way. What can be the main reason SUppose i put a formula on the column then Everytime user import the data he need formula which might be not a good idea, Is there something I can do when I m importing or just like wondering what could be done?
10/22/2014 1:34:00 AM or PM
Here's one approach:
Substitute dots with slashes
Use DATEVALUE, TIMEVALUE functions on relevant subsections of this substituted string. Subsections are fetched using LEFT and RIGHT string functions.
These return a serial number for dates (days since 1900) and time (a floating point between 0 and 1). When summed, the value can be represented as both date and time, in a format of your choice, as shown below:
Or, showing formulas:
EDIT: adding all-in-one formula.
Note that this will give you the serial value (41934.5652777778), which can then be formated using the built in formats for dates / times--just select the one you want. This does not actually render a string:
=DATEVALUE(LEFT(SUBSTITUTE(A1,".","/"),10))+TIMEVALUE(RIGHT(SUBSTITUTE(A1,".","/"),8))
If, however, you do want a string returned, you can use the TEXT function.
=TEXT(DATEVALUE(LEFT(SUBSTITUTE(A1,".","/"),10))+TIMEVALUE(RIGHT(SUBSTITUTE(A1,".","/"),8)),"m/d/yyyy h:mm AM/PM")
(This is done in libreoffice, but the same formulas and arguments exist in MS Excel)

Format all cells in column from date to text

I have an excel document with about 500 rows.
I need to format all the cells in , let's say, B column from date to text.
This is how it looks like now:
2012-06-15
2012-06-01
2012-06-14
What it looks like when formated to text:
41075
41061
41074
It has come to my understanding that this is a timestamp representing days since 1st januari 1900, right? Anyhow, this is not what I want. I want the value of the field to be exactly what it is but with the column type of text. I've found various solutions for this using functions like this: =TEXT(B1, "yyyy-mm-dd") but that is not reformating the cell, it is extracting a value from one cell, reformat it and represent is as text in another.
The rule I'm after: I want all cells in B column to have the type text without changing the value
Thanks!
If you have a situation where columns A to D are dates of 500 rows you then:
Use the =TEXT(A1, "yyyy-mm-dd") function you describe in cell E1.
Copy this formula 4 columns wide, and 500 rows down.
Then copy and paste values to the preceding cells.
Copy Example:
Output:
You're right, Excel stores dates internally as number of days since January 1st, 1900 (apart from a minor leap year bug).
Thus, I'm afraid you cannot have both:
Either you keep the value e.g. (41075) and simply format it as a date, so it'll be displayed as 2012-06-15 -
Or you convert it to text format - but then you either
Lose the underlying value - if you convert it to the format you wish with a text function as you mentioned
Keep the value (41075), but cannot see the date
If you are typing in the values you can by adding a ' before the values to keep it as text.
e.g.
But depending on the method the third party service uses to import these values this may not work and I bet you will not get around it unless you export it to a text editor and import it again.
Also try to play with diferent types of text for your third party service, e.g. "2012-06-15" as some see the quotes and remove them.

Some dates recognized as dates, some dates not recognized. Why?

Here is a list of dates:
04-22-11
12-19-11
11-04-11
12-08-11
09-27-11
09-27-11
04-01-11
When you copy this list in Excel, some of them are recognized as dates, others not, in the following manner:
04-22-11
12-19-11
11-04-11 (date)
12-08-11 (date)
09-27-11
09-27-11
04-01-11 (date)
Does anyone know why? And how to force Excel to recognize all list items as dates?
Many thanks!
It is caused by Excel auto-recognizing/formatting the cell contents, but in unclear/inconsistent ways.
Fixing it is not that hard...
Check out this forum post:
http://www.pcreview.co.uk/forums/excel-not-recognizing-dates-dates-t3139469.html
The steps in short:
Select only the column of "dates"
Click Data > Text to Columns
Click Next
Click Next
In step 3 of the wizard, check "Date" under Col data format, then
choose: "DMY" from the droplist.
Click Finish
This is caused by the regional settings of your computer.
When you paste data into excel it is only a bunch of strings (not dates).
Excel has some logic in it to recognize your current data formats as well as a few similar date formats or obvious date formats where it can assume it is a date. When it is able to match your pasted in data to a valid date then it will format it as a date in the cell it is in.
Your specific example is due to your list of dates is formatted as "m/d/yy" which is US format. it pastes correctly in my excel because I have my regional setting set to "US English" (even though I'm Canadian :) )
If you system is set to Canadian English/French format then it will expect "d/m/yy" format and not recognize any date where the month is > 13.
The best way to import data, that contains dates, into excel is to copy it in this format.
2011-04-22
2011-12-19
2011-11-04
2011-12-08
2011-09-27
2011-09-27
2011-04-01
Which is "yyyy-MM-dd", this format is recognized the same way on every computer I have ever seen (is often refered to as ODBC format or Standard format) where the units are always from greatest to least weight ("yyyy-MM-dd HH:mm:ss.fff") another side effect is it will sort correctly as a string.
To avoid swaping your regional settings back and forth you may consider writting a macro in excel to paste the data in. a simple popup format and some basic logic to reformat the dates would not be too difficult.
In your case it is probably taking them in DD-MM-YY format, not MM-DD-YY.
The quickest and easiest way to fix this is to do a find and replace on your date seperator, with the same separator.
For example in this case Find "-" and Replace with "-", not sure why this works but you will find all dates are right-aligned as they should be after doing this.
Here is what worked for me. I highlighted the column with all my dates. Under the Data tab, I selected 'text to columns' and selected the 'Delimited' box, I hit next and finish. Although it didn't seem like anything changed, Excel now read the column as dates and I was able to sort by dates.
The simplest solution is to put yy,mm,dd into the date() formula by first extracting them with left(), mid() and right(). In this case, assuming your input date is in A1:
=date(right(A1,2)+100,left(A1,2),mid(A1,4,2))
Explanation of above:
=right(A1,2) gets the last two digits in the cell (yy). We add 100 because it defaults to 1911 instead 2011 (omit +100 if it doesn't do that on yours)
=left(A1,2) gets the first two digits in the cell (mm).
=mid(A1,4,2) gets 2 digits in the middle of the cell, starting at 4th digit (dd).
Why this happens in the first place:
I come across this problem all the time when I import Canadian bank data into excel. In short, your input date format does not match your regional settings.
Seems your setting mean Excel wants date input as either DD-MM-YY or YY-MM-DD, but your input data is formatted as MM-DD-YY.
So, excel sees your days as months and vice-versa, which means any date with day below 12 will be recognized as a date, BUT THE WRONG DATE (month and day reversed) and any date with day above 12 won't be recognized as a date at all, because Excel sees the day as a 13th+ month.
Unfortunately, you can't just change the formatting, because Excel has already locked those day/month assignments in place, and you just end up moving what Excel THINKS are days and months around visually, not reassigning them.
Frankly, it is surprising to me there is not a date-reverse tool in excel, because I would think this happens all the time. But the formula above does it pretty simply.
NOTE: if your dates don't have leading zeros (i.e. 4/8/11 vs 04/08/12) it gets trickier because you have to extract different amounts of digits depending on the date (i.e. 4/9/11 vs 4/10/11). You then have to build a couple if statements in your formula. Gross.
Here is what worked for me on a mm/dd/yyyy format:
=DATE(VALUE(RIGHT(A1,4)),VALUE(LEFT(A1,2)),VALUE(MID(A1,4,2)))
Convert the cell with the formula to date format and drag the formula down.
Right-click on the column header and select Format Cells, the chose Date and select the desired date format. Those that are not recognized are ambiguous, and as such not interpreted as anything but that is resolved after applying formatting to the column. Note that for me, in Excel 2002 SP3, the dates given above are automatically and correctly interpreted as dates when pasting.
A workaround for this problem consists in temporarily changing your regional settings, so the date format of the CSV imported file "matches" the regional settings one.
Open Office seems to work in a similar way for that issue, see: http://www.oooforum.org/forum/viewtopic.phtml?t=85898
I come across this problem when I tried to convert to Australian date format in excel. I split the cell with delimiter and used the following code from split cells then altered the issue areas.
=date(dd,mm,yy)

Resources