Please see image for clearer description of the problem.
When pasting dates into excel it seems to SOMETIMES honor the local system settings for dates (set in Win10 intl.cpl) : in my case UK formatting i.e. DD-MM-YY, but othertimes it uses US formatting i.e. MM-DD-YY. I cannot workout the rules it is following, making it hard to accurately predict how it will interpret large pasted data sets of dates.
As a test, I took the string "02/11/2022 07:00" and pasted into excel. It correctly interpreted this in UK format as a date (in cell B2) as the date: 2-Nov-22 07:00
The source database where I'm copying the date datasets from appends various characters to some dates as markers that unfortunately cannot be removed before copying. So a date might look like: "02/11/2022 07:00*" (note the appended asterix). I need to remove the asterix in excel to make the date usable in excel.
That's where the wierdness comes in:
In the first case (row 3) if I use excel worksheet formulas to trim the asterix with LEFT function, the string remains a string and is not recognised as a date.
In the second case (row 4) if I use vba to trim the asterix with LEFT, the string is recognised in US format (i.e. not honoring local settings) and I get an incorrect date of 11-Feb-22 07:00. So two strange things here:
the excel worksheet LEFT trim result does NOT get recognised as a date, the vba one DOES; and
the vba trim result IS recognised as a date but is interpreted with US settings, even though the local settings are honored in the original 'clean' string case
In the third case (row 5) if I use vba to trim and CDate the string in one line VBA line, excel recognises a date and recognises it correctly in UK format. However if this is done in two steps (trim in one line, paste to cell, and then Cdate the resultant string), excel interferes when the cell gets hold of the string and I get a US date recognised in the middle.
What is most confusing is that if i post a 'clean' date string, excel honors the local interpretation. If I need to manipulate the string to remove artefacts and put a cleaned string in a cell, it doesn't honor local interpretation.
Note: I understand the difference of regional cell FORMATTING which just tells excel how to DISPLAY the date. This question is to do with excel converting a string to a numeric value by sometimes assuming a US date, and othertimes assuming a UK date!
Any definitive advice on how to force excel/vba into using the local date format when it INTERPRETS date strings?
Assuming your pasted strings do not include the visible quotation marks you show
Row 1: Normal behavior
Row 2: The string functions (eg LEFT) return text which will not be auto-converted. To convert to a date value, wrap the results with either the double-unary (--), VALUE function, or DATEVALUE function.
Row 3: VBA is US-centric in converting unqualified date strings
Row 4: CDate respects the windows regional settings.
In a report I have a cell that contains logs. In that series of logs I want to extract the part where it says "Transaction ID:111-2222".
I tried using the following function but it does not work systematically as the number I'm looking for is not always in the same position within the cell.
=IF(COUNTIF(A2;"*Transaction ID:*");MID(A2;127;7);"no")
Any ideas? Thanks!
I have cells formatted as date with type mm/dd/yy. The dates display correctly while in the date data type. Switching this to text obviously reveals the excel datevalues. using text to columns however does not retain the format specified of mm/dd/yy, and instead always removes the leading zeroes and uses the full year e.g. 1/4/2019. Is there any way to get the text to columns to interpret the format I actually have set?
You can always convert a date to text using the TEXT() function.
For example: =TEXT(A1,"mm/dd/yy") converts the date value in cell A1 to mm/dd/yy format.
I am trying to open a CSV file which contains a column named ts which has timestamp in the following pattern throughout the file:
12/31/2016 20:40
mm/dd/yyyy hh:mm
Now when I open this in Excel, some of them are getting recognized some not.
The problem seems to be that Excel is automatically recognising it in dd/mm/yyyy hh:mm format so when a date is 11/13/2016 0:00, it is unable to recognise it(because of 13th Month).
How to fix this?
You'll find that even when Excel is recognizing dates, it's getting the months and days back to front.
When opening a .csv file directly (e.g. by double clicking it from Windows Explorer or choosing File > Open from within Excel), Excel will try to parse any dates according to your local time format. The only way to change how dates are parsed when opening a file directly is to change your local time format, which you probably don't want to do.
The workaround is to open the file from within Excel using the Text Import Wizard, where you can explicitly state the format in which dates have been stored in the text file.
Open a new workbook
Go to the Data tab; in the Get External Data group, click From Text
Select your file and click Import
Step 1: Choose Delimited and select Next
Step 2: If it's a true .csv, choose Comma as your only delimiter. (Note that quite often, data exported from other systems is tab-delimited rather than comma separated. However, the .csv file extension is still used to indicate that the file is opened in Excel (or similar). If choosing Comma isn't splitting your columns correctly, try choosing Tab as your delimiter instead. When your data has been split into columns correctly, press Next.)
Step 3: Select the column that has dates, then set the Column data format to Date and in the drop down, choose MDY. It should look like this:
Click Finish
Choose where you want the data to go and click OK
You should now have the data open, with the dates correctly interpreted and also displaying in your local date format (dd/mm/yyyy).
If you want to keep the full date and time in one column, then additional work is required because there's no way of telling Excel to correctly interpret a date/time string that doesn't match your local format.
Start by following the above steps, but at step 6, choose Text as the data format instead. This is necessary to ensure Excel doesn't try to interpret any dates (where day is less than 12).
Then, if your dates are always in mm/dd/yyyy hh:mm format (including leading zeroes for single digit days, months and hours), then the following formula will convert a date/time string that is in cell A1 to a date/time serial that you can format and work with as normal:
=DATE(MID(A1,7,4),LEFT(A1,2),MID(A1,4,2)) + TIMEVALUE(RIGHT(A1,5))
This is happening because the output date you got is in text format, not in date format. Here is the trick to resolve your case to get the output in mm/dd/yyyy hh:mm format. You can change the format to your desired one.
If text date is in A column, then formula is -
=DATE(MID(A3,SEARCH("/",$A3,SEARCH("/",$A3,1)+1)+1,4),LEFT(A3,SEARCH("/",A3,1)-1),MID($A3,SEARCH("/",$A3,1)+1,SEARCH("/",$A3,SEARCH("/",$A3,1)+1)-SEARCH("/",$A3,1)-1))+TIME(HOUR(RIGHT(A3,LEN(A3)-SEARCH(" ",A3,1))),MINUTE(RIGHT(A3,LEN(A3)-SEARCH(" ",A3,1))),SECOND(RIGHT(A3,LEN(A3)-SEARCH(" ",A3,1))))
Hope this helps. Rate if satisfied. :)
I've left the Text Import Wizard approach as a separate answer, because it has some useful info. However, I've realized that if we're heading down the path of needing to use a formula, then we might as well just use a formula after opening the file normally!
The following formula works on all date/times that were stored as mm/dd/yyyy hh:mm
=IF(ISNUMBER(A1),DATE(YEAR(A1),DAY(A1),MONTH(A1))+A1-INT(A1),DATE(MID(A1,7,4),LEFT(A1,2),MID(A1,4,2)) + TIMEVALUE(RIGHT(A1,5)))
The formula first checks whether Excel has interpreted the value as a date, which happens when the day is less than or equal to 12. If it has, then Excel has swapped day and month, so the formula swaps them back. Alternatively, if Excel hasn't interpreted the value as a date (which happens when the day is greater than 12), it will still be text and a date/time is generated after rearranging the text string.
Hey guys I have a situation where I need to format a column to display APR(%) values in a certain way. Basically the values should be formatted like below:
Raw input Formatted value
========= ===============
0 0
0.0 0
4.4566 4.5
5.00 5
6 6
6.4 6.4
I tried creating this formula below but for some reason it doesn't round the number to 2 decimal places.
=INT(ROUND(A1,1)*100)/100
What am I doing wrong? Or is there a better way to handle this?
UPDATE: So I am applying the function to the same cell as the number is in. For instance the A1 cell contains 4.566 value and I applied the function to that same cell and this doesn't seem to be working for Excel. Any other ways to do this?
P.S: Im using the MS Excel for Mac
Two steps
Format the cells to Number with one decimal place
Conditionally format the cells to a Number Format of General if the value is an integer
EDIT: Since you cannot conditionally format the number format in Excel for MAC, there are several workarounds.
If you do not mind changing the actual value, add a column which you will use to display the result. Format the Column as "General", and use this formula (assuming your "real data" is in column A:
=IF(A1<>INT(A1),ROUND(A1,1),A1)
Other options that may work would include using an event-triggered macro (if that can be done in Excel for Mac); and possibly you can create the worksheet in Excel for Windows and the conditional format might be recognized in Excel for Mac, even if you can't create it there.
As explained in the documentation here,
Suppose that cell A1 contains 823.7825.
...
=ROUND(A1,2) ... equals 823.78
You should be able to therefore apply this to your entire column to get the precision that you are after.
Rather than using =INT(<another_cell_value>*100)/100 to derive the format you want, simply specify a custom format with the following:
#,###.##
This way, you only get the number of decimal places that you specified in the ROUND function.