How to get excel to recognize a number input as a date - excel

I want to change the default format of dates in excel sheets to follow a format that is 'yymmdd'. I dont want to include any slashes periods or dashes to separate the elements of the date. For example the 14th of May 2022, would simply be displayed as 220514.
The problem I'm running into is that excel sees me entering 220514 as a number and converts it to a date using its own method of adding the number I enter to the default start date of 01/01/1900. If I manually change the date in the formula bar to what I want it to be, it will display correctly, but this wont be feasible if I have to enter a large amount of data. If I enter the date in a format with slashes (22/05/14) it also works, but I want to avoid having to do that if possible. Is there a workaround for this?

Related

How to convert date in the form ##.##.## to the form ##/##/## in Excel?

Trying to calculate age from date of birth (which is inputted by other users), however when someone enters the date with dots in between (i.e. 13.02.2000) the function doesn't work.
The function I'm using to calculate age is: =(TODAY()-D7)/365.25 Where D7 contains the DoB.
Would like the date in other formats to be changed automatically, without the need for an extra column.
I've tried using Format Cells, however it doesn't work.
One method is to use Data Validation:
Select the cell(s) where the date(s) will be entered
Data-->Validation
Allow Date
Data: between (or anything else that will be ok with various dates)
Insert an appropriate range
You can try the following formula. But note this will work only for normal dates and also for the scenario where a date is entered as text using dots as the delimiter:
=(TODAY()- IF(ISTEXT(D7),VALUE(SUBSTITUTE(D7,".","/")),D7) )/365.25

Excel wrong timestamp format recognition

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.

Excel formula is working for one format of time not for another

I am developing the attendance sheet using excel, So inputs are In time and outtime.There are four conditions.
For eg:In time:09:00 Out time:19:30 Ans: 09:30
Formula:
IF((AND(L15>TIME(9,30,0),L16<TIME(19,30,0))),L16-L15,<br>IF(AND(L15<TIME(9,30,0),L16>TIME(19,30,0)),"10:00",<br>IF(AND(L15<TIME(9,30,0),L16<TIME(19,30,0)),L16-TIME(9,30,0),<br>IF(AND(L15>TIME(9,30,0),TIME(19,30,0)<L16),TIME(19,30,0)-L15,"0")))).
Formula is not working for format like 09:00, but its working for 9:00.
If there are leading zeros in time, then it doesnt work.
Your 09:00 time format is most likely read by excel as text. If it is aligned left it is read as text.
Thus you need to change the data that is entered. You could do so with a function that ensures that a number (or time) is entered as text is converted to a number such as =VALUE()
Try this:
IF((AND(VALUE(L15)>TIME(9,30,0),L16<TIME(19,30,0))),L16-VALUE(L15),<br>IF(AND(VALUE(L15)<TIME(9,30,0),L16>TIME(19,30,0)),"10:00",<br>IF(AND(VALUE(L15)<TIME(9,30,0),L16<TIME(19,30,0)),L16-TIME(9,30,0),<br>IF(AND(VALUE(L15)>TIME(9,30,0),TIME(19,30,0)<L16),TIME(19,30,0)-VALUE(L15),"0"))))
If you change the cell format to a time format without leading zero, it will not show the leading zero (09:00 is changed to 9:00) and your function should work.

Excel #Value error when using DATEVALUE function

In cell A2 I have 7/21/2014 12:44:36 PM
When I use DATEVALUE(LEFT(A2;FIND(" ";A2)-1)) I get the error #VALUE.
When I use LEFT(A2;FIND(" ";A2)-1) I get 7/21/2014.
What do I need do that function DATEVALUE(LEFT(A2;FIND(" ";A2)-1)) to return just the date?
DATEVALUE() is designed to make a Date out of plain text. Your cell is currently a Date/Time, which is a numeric value. I recommend using one of the following solutions to get the date from the cell.
Using DATE()
This is the cleanest option and the method that I would recommend.
=DATE(YEAR(A2),MONTH(A2),DAY(A2))
YEAR() gets the Year value from the cell, MONTH() gets the Month value, and DAY() gets the Day value. The DATE() function takes a Year, Month, and Day value, so by passing them into DATE() we can get the Date value from A2.
Using INT()
If we look at the numeric value of your Date in A2, we see that it is 41841.5309722222. The whole portion of the number (41841.) is the date and the decimal portion (.5309722222) is the time. So if we take INT(A2) to convert this value to an integer, we will lose the decimal portion so that all that remains (41841) is the date. So this is our formula for using INT()
=INT(A2)
The same idea can be accomplished with ROUNDDOWN(A2,0) or =FLOOR.MATH(A2) or =FLOOR(A2,1).
Using DATEVALUE()
While the first solution is the cleanest, there is a way to do this with DATEVALUE() that involves converting the cell into Text first. The TEXT() function takes a value and a format string, so we format the cell value as Text as follows
=TEXT(A2,"yyyy-mm-dd")
And this gives us
2014-07-21
We then pass that result into DATEVALUE()
=DATEVALUE(TEXT(A2,"yyyy-mm-dd"))
You will need to format the result as a date.
Using LEFT() and DATEVALUE()
Based on this Stackoverflow question that I found, it appears the issue could be a result of inconsistent formatting, so you might try this solution
=DATEVALUE(LEFT(A2,FIND(" ",A2)-1))
I have included my results with this and the other methods in a screenshot below. You can see by my use of the TYPE() command below the value that I tested this on both a number and text.
Results
Formatting
I'm assuming you want just the date for calculation purposes, but if you just want to display the date, you can format the cell to only show the date and ignore the time element although the time element will still be present in the cell. I'm assuming you know about this, but since you didn't specify, it is a possible solution.
Please try:
=INT(A2)
and format the result to suit.
In a comment I have just seen you mention "=INT(A2) return #VALUE!" so I would suggest selecting your date cells, DATA > Data Tools, - Text to Columns, Delimited, Delimiters Tab (only), and at Step 3 of 3 choose MDY for Date: or change your locale to say USA.
If neither work try =INT(TRIM(A2)) in case you have leading spaces (though not showing them).
If still not working, try applying =CLEAN.
If still nothing works then some further details of where your dates are coming from and how imported would be helpful, and of your locale and default date format.
Date macros are depending on the system date format and based on configured system date format the macros can fail to work. Try below solution. We faced similar issue after open excel file sent by me on another laptop where system date/time format was different. On destination laptop formulas using date functions started giving error. After following below steps errors disappeared.
Left click on bottom right portion of task bar where time is displayed
Click on date and time settings
Click on change date and time
Change calendar settings
Click on reset to go back to original values
Click on OK on all opened dialogues
Now excel formula error should disappear
SIMPLE SOLUTION - I found a solve that worked very well:
=DATEVALUE(TEXT([CELL],"MM/DD/YYYY")
Effectively this lets me convert any value into text, then back into date. It fixed my Datevalue error and I can use it regardless of the original cell formatting.

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