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)
Related
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
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.
I have a worksheet that contains data downloaded directly from a database. It contains all texts including text-format dates and revenues. I want to convert 1 column from text to numbers, and 1 column of text (of dates) into dates format so that I can check for year and month to use SUMIFS() function.
Additional information: as you can see from the attached image, in the Close Date column, the dates are all in 30.11.2016 format, connected with dots, and is in a dd.mm.yyyy expression but all in texts.
In the Amount column, the number of revenues are actually in a European expression, 50000,00 which actually means 50000.00, and 50000,00 is in text format.
Currently, I am using the LEFT(), MID(), RIGHT() functions to extract the strings of numbers of year, month, and day, and then DATE() function to convert to dates.
For the Amount column numbers, I am simply using TexttoColumns to do the manual work of conversion.
Is there a way to do these works in VBA? Can someone help me with the codes? I have some basic programming experience, but I have never exposed myself to VBA before.
Millions of THANKS! I really appreciate it!
You can use Power Query for that. No coding required. Start a query and click the ribbon icons in the Query Editor to transform data, for example replace commas with dots, change type from text to number etc. Each action will be recorded as a step, using the M language. If desired, the M code can be manipulated, but for something this simple you don't need to.
The query can be refreshed when the source data changes.
Power Query is a free add-in from Microsoft for Excel 2010 and 2013 and it is built into Excel 2016 as Get & Transform.
I would just use the Find and Replace function. Highlight the date column, find "." and replace with "/". Then that will give you some dates. You can do the same with "," and replace with "." - if it still appears as text, then you can convert to numbers from there. (in any case, VBA will be just harder work for you)
My data is extracted from an application and it has a text that looks like a date/time in excel. How do I actually convert "3/24/2016 11:22:07 PM" (in text) to a real date/time conversion? I've tried formatting the cells but it doesn't work.
For a date conversion:
=DATEVALUE(TEXT(A1,"MM/DD/YYYY"))
For a time conversion:
=TIMEVALUE(TEXT(A1,"HH:MM:SS"))
For datetime conversion:
=DATEVALUE(TEXT(A1,"MM/DD/YYYY"))+TIMEVALUE(TEXT(A1,"HH:MM:SS"))
Where A1 has the data you wish to convert.
By the way, then you may wish to format the cell to a date/time or whatever.
Hope that helps.
1) try using the DATEVALUE function and see if that works for you.
2) A more reliable way, since datevalue does not always work is to strip the text out manually and insert it into and excel date value. You are going to want to use a combination of the following functions:
DATE
TIME
IF
FIND
MID
LEFT
RIGHT
LEN
Now in my opinion the easiest way to do this is to work with multiple helper columns to build out all the steps. One column per step. When you get your final answer, you can substitute or copy paste your formulas from the helper columns into the final formula until you are left with one variable. The reason I say this is that the final formula referring to only 1 variable gets rather lengthy/ugly and very hard to trouble shoot if you make a typo, forget a bracket or something goes wrong. When I did this approach I used a totally of 14 columns (includes final formula). When I packed it all up into 1 formula it resulted in this:
DATE(RIGHT(LEFT(A3,FIND(" ",A3)-1),4),LEFT(LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))-1),MID(LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))+1,FIND("/",LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))+1)-FIND("/",LEFT(A3,FIND(" ",A3)-1))-1))+TIME(LEFT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1)+IF(AND(LEFT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1)<12,RIGHT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),2)="AM"),0,12),MID(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1,FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1)-FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1),MID(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1)+1,2))
Note it is set up using cell A3 as the one with the time as text that needs formatting.
3) You should also be able to use excel's text to column function located on the DATA ribbon about half way across.
4) And of course there will be a way to code it through VBA as an option as well.
=DATEVALUE(A1)+TIMEVALUE(A1) seems to work as well, since each function only returns the value corresponding to what it recognizes in the string. That is, DATEVALUE() ignores the time component, while TIMEVALUE() ignores the date component.
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.