Difference between two date columns formatted as General - excel

I have two columns in Excel, formatted as General - with this data:
Column A Column B
11/2/2014 9:12:27 AM 12/3/2014 2:00:00 AM
How can I find the difference in hours between them, if they are formatted as "General" and not "Date"?
Thank you for any advice,
Mark

I assume that means these are actually text formatted datetimes - you can test by trying to change the format, e.g. try to change to "Number" - if nothing changes theses are text values.
You can still subtract, though, if the datetimes are in a valid format for your region.
Try using a simple subtraction like
=B1-A1
custom format result cell as [h]:mm
I get the result 688:47 (which assumes that the first timestamp is 11th Feb not 2nd November)

Please try:
=VALUE(B1)-VALUE(A1)
custom formatted as[HH].

Related

Excel not properly comparing dates, despite same cell format

I have two date rows. Both are formatted as dates. When I do a logic test to see whether the two dates, excel is not recognizing them as the same.
Here is a screenshot of the cells:
This is to confirm that both cell rows are formatted as date:
This is to confirm that the equality check row is referencing the right cells:
I'm stumped. Does anyone have any idea what's going on here? Thanks
If you have confirmed that both are actually dates, and not text masquerading as dates, then time is most likely the issue. Note that time is represented via the decimal such that .5 equals noon.
Assuming you just want to know if the dates match independent of time you can use
INT(G4) = INT(G6)
If you want to compare just the dates use:
=Floor(G4,1) = Floor(G6,1)
Format can mask the real cell value. Format both cells as General, then you can see the difference.
If a cell stays a "date" when it is formatted as General, then the cell is most likely text, not a date.
When formatted as General, you can clearly see if the number has any decimals, i.e. time on top of the date.

using if with Today() and cutom date cells usually return True?

I received excel sheet with dates in column U as (Jul 8, 2009).
I changed cells format to custom date (mmm d, yyyy)
now in column V, I added below if statement
=IF(U9="";"No Date";IF(U9>TODAY();"warranty";"expired"))
my problem is: why all values returned as "warranty" what ever date in column U?
May 10, 2016.....warranty
Jul 8, 2011.........warranty
Jan 1, 2017........warranty
Jul 23, 2011........warranty
You need to turn on the automatic calculation:Options>Formulas>Workbook calculation>Automatic
Or you can turn it on in the formulas tab in the tool bar:
It sounds like the data in the sheet might be wrong - have you checked its value and compared this to the value of today? (use the value function on the cell is probably easiest)
There is a '1904' date setting deep in the bowels of the options (under advanced) which some systems use - whereby the dates started at a different point that Excels usual. This means that today would not match today - and the situation you are describing is possible.
The dates you received might have been formatted as Text. In that case changing the cell format won't convert it to date, and some formulas and expressions will regard it as text and not as a date value.
To verify this try to change the date format on one of the date cells that calculate incorrectly to some other date format or number, and you will see there is no effect.
One solution is to add the DATEVALUE() function to your formula:
=IF(U9="";"No Date";IF(DATEVALUE(U9)>TODAY();"warranty";"expired"))
This will work only if all of your dates are formatted as text.
Another solution is to run Text to Columns from the Data menu. This process has the side-effect of converting data types.
Select your dates column and run Text to Columns.
Choose Delimited and click Next.
Remove any selected Delimiters and click Next.
You may choose General or Date and click Finish.
After that your original formula should work correctly.
Addition:
It seems this is not a typical problem and it might have to do with the machine locale settings and date format recognition.
A possible workaround can be using this formula to retrieve the correct date value from a date text formatted as MMM d, yyyy:
=DATE(RIGHT(U9,4),
MATCH(LEFT(U9,3),
{"Jan","Feb","Mar","April","May","jun","Jul","Aug","Sep","Oct","Nov","Dec"}
,0),
NUMBERVALUE(MID(U9,5,2)))
For easy copy:
DATE(RIGHT(U9,4),MATCH(LEFT(U9,3),{"Jan","Feb","Mar","April","May","jun","Jul","Aug","Sep","Oct","Nov","Dec"},0),NUMBERVALUE(MID(U9,5,2)))
Replace the U9 part of your original formula with this formula.

Convert number to YYYYMM

I have following numbers, which actually represent dates in the YYYYMM format:
201301
201302
201303
...
When I try to format the cells to date fields, Excel always overwrites the original dates and creates some crazy dates, that have nothing in common with the actual ones.
How can I bring Excel to convert it properly?
Excel (by default) uses the 1900 date system. This simply means that the date 1 Jan 1900 has a true numeric value of 1, 2 Jan 1900 has a value of 2 etc. These values are called "serial values" in Excel and it is these serial values that allows us to use dates in calculations. which was discussed here.
So that explains why your data reflects a different date when you try to format is as Date.
What you need to do then is to transform it into a complete readable date format Excel recognize.
As is, Excel will use its default Serial Value conversion.
If you have your data in starting in A1, enter this in B1.
=DATEVALUE(SUBSTITUTE(A1,LEFT(A1,4),LEFT(A1,4)&"-")&"-01")
Above formula will then create a valid Date that Excel can interpret and read correctly.
Result will be:
41275
41306
41334
When you format it as Date, it will equate to the 1st day of every month.
1/1/2013
2/1/2013
3/1/2013
You can just fix the formatting using Custom Format to get YYYYMM as seen below:
If your range is small enough (in the example all 2013) then no formula is required. Replace 13 with 13-, apply Text to Columns with Tab as the delimiter and at Step 3 choose Date and YMD.
You can use the DATE and LEFT/RIGHT functions.
Assuming that format is consistent (i.e. 4 characters for year, 2 characters for month), to convert cell A1:
=DATE(LEFT(A1,4), RIGHT(A1,2), 1)
This will assume the first day of the month for the date (I assume that's irrelevant for you). You can then format the cell as you want.
Can you use formula in Excel to solve this..
A sample formula is given below
=DATE(MID(CELLID,1,4),MID(CELLID,5,2), 1)

date conversion formula in excel

I have some dated in this format "09-MAY-13 06.42.46.097127000 PM" and need to convert to this format "2013-05-09T18:42:47.132Z". my goal is to find out which happend earlier. I am not sure how to format these dates.
2013-05-09T18:42:47.132Z 09-MAY-13 06.42.46.097127000 PM
2013-05-08T20:56:55.821Z 06-MAY-13 03.22.09.129443000 PM
2013-05-08T20:51:45.287Z 06-MAY-13 03.03.22.975700000 PM
2013-05-08T20:55:34.719Z 06-MAY-13 10.40.55.924181000 PM
How I can do that??
I originally posted an answer which converted one of your formats to the other. I now see that you need to compare them, so you can convert this format in A2 to date/number values ....
09-MAY-13 06.42.46.097127000 PM
.....with this formula
=SUBSTITUTE(SUBSTITUTE(A2,".",":",1),".",":",1)+0
and this format in A3
2013-05-09T18:42:46.097z
....with this formula
=SUBSTITUTE(SUBSTITUTE(A3,"T"," "),"z","")+0
You can format the results how you like, leave as numbers or format as m/d/yyyy hh:mm:ss.000 or similar. you can now compare easily with a formula like
=B2>B3
or get the smaller or larger with MIN or MAX
If have a value of your original style in cell A1, place the following formula in a different cell:
=DATE((2000+MID(A1,8,2)),MATCH(MID(A1,4,3),{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"},0),LEFT(A1,2))+TIME(MID(A1,11,2)+IF(RIGHT(A1,2)="PM",12,0),MID(A1,14,2),MID(A1,17,12))
Then, in that target cell, apply the following format:
yyyy-mm-ddThh:mm:ssZ
Please note the following:
This assumes that all of your months are 3 characters (JAN, FEB, MAR). Since your example was "MAY" (already 3 characters), I don't know with certainty how your other months appear. Longer month names complicate the formula a bit. I can help with this if you need it and don't know how to do it.
I couldn't find a way to force Excel to display fractional seconds in the context of such complex date/time formatting, even though your example showed seconds subdivided to the thousandths. Hopefully this isn't a deal-breaker. If it's necessary to display fractional seconds, you may need to handle this with a separate formula to display the result as text, independent of the formula above, which you can use for your calculations of which date came earlier.
To add to Joe's answer...
To get Excel to compare one column to the other you need to do the same sort of manipulation from the first column as the second.
That would look like
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))+TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,5))
Once you have a new column for each of these transformations it should be simple to have Excel compare them.

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.

Resources