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)
Related
I am trying to change the date format of my cells in excel to another date format. Currently it is in this format: apr, 10, 2017 01:58:24 PM. I would like to have it in a normal format like dd-mm-yyyy without the time, but I can not get it to work with the formatting in excel.
Thanks in advance,
Kester
You could use this:
=(MID(A2,FIND(",",A2)+2,FIND(",",SUBSTITUTE(A2,",","#",1))-FIND(",",A2)-2)&"-"&LEFT(A2,FIND(",",A2)-1)&"-"&MID(A2,FIND(",",SUBSTITUTE(A2,",","#",1))+2,LEN(A2)))*1
Which is basically a bit of string manipulation (and some substitution of , to # to help) to put it in the generic format 'd-m-y h:m:s t', which excel understands, then multiply the string by 1 to force into a number (in this case 42835.58222); which you only have to format as date (important!):
Edit: Per comments, the first comma doesn't actually exist, so the revised formula:
=(MID(A2,FIND(" ",A2)+1,FIND(",",A2)-FIND(" ",A2)-1)&"-"&LEFT(A2,FIND(" ",A2)-1)&"-"&MID(A2,FIND(",",A2)+2,LEN(A2)))*1
With data in A1, in B1 enter:
=DATE(MID(A1,10,4),MATCH(LEFT(A1,3),{"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"},0),MID(A1,6,2))
and apply desired formatting:
(this results in a genuine Excel date that can be used in sorts, calculations, etc.)(this assumes that the day field is always two digits)(if your month list is in a language other than English, edit the month list)
I have a cell with this value: Sat 24 Jan 2009 01:23:12
I defined a custom date format: jjj jj mmm aaaa hh:mm:ss
.but I can't do arithmetic on this date cell. For example I can't do "CELL + 1 hour"
to add an hour to time just add +(1/24) to the formula or =cell+(1/24) in a new column
Excel doesn't exactly understand a text as a date when a custom formatting is created, so the way you described it in your question is not really going to work (unless someone actually knows a way to do that). I'd suggest using a helper formula that will work for the specific format that you have:
=SUBSTITUTE(SUBSTITUTE(MID(A1,5,20)," ","-",1)," ","-",1)*1
If you omit the *1 I have at the end, you should see the text I'm using before multiplying by 1 (that's where Excel attempts to convert the text to number, which is a date format that Excel can understand).
The above should give you a number with some decimals. Format it as date, with the formatting of your choice and you should be good to go. I used dd/mm/yyyy hh:mm:ss and got this:
The MID basically removes the weekday part, and the two SUBSTITUTEs replace the first 2 spaces with a dash each, and that's something Excel can understand as datetime.
I have a date field where the format is (example) 20170101.
When I try to convert this field to short date, it comes up as "###".
I need the date in the format of 1/1/2017.
Can someone help?
Thanks!
The data is not a date but a number and by simply changing the format will try to return a date that is 20,170,101 days from 1/1/1900. And Excel stops recognizing dates after 12/31/9999. This would be well beyond that, roughly 45 thousand years beyond that.
you can use a helper column with the following formula:
=--REPLACE(REPLACE(A1,7,0,"/"),5,0,"/")
Format it as desired.
Then you can copy paste just the value over the original.
I have been searching it for an hour but unfortunately nothing found that actually work. I have an excel sheet with a column having date in it. Current date format is dd.mm.yyyy but I want to change date format to yyyy/mm/dd for entire cell.
OPTION 1)
Assuming that you source date that is in the number format dd.mm.yyyy stored as an excel date serial and only formatted to display as dd.mm.yyyy then the best fix is to select the cells you want to modify. Go to your home tab, and select the number format and change it to General. See Green circles in image below. IF the format is already set to general, or when you switch it to general your numbers do not change, then it is most likely that your date in dd.mm.yyyy format is actually text. and will needed to be converted as per OPTION 2 below. However, if the number does change when you set it to general, select the arrow in the bottom right corner of the number area (see red circle).
After clicking the arrow in the red circle you should see a screen similar to the one below:
Select Custom from the category list on the left, and then in the Type bar enter the format you want which is yyyy/mm/dd.
OPTION 2
=date(Right(A1,4),mid(A1,4,2),left(A1,2))
This assumes your original date is a string stored in A1, and converts the string to a date serial in the form excel stores dates in.1 You can copy this formula down beside you dates. You can then apply cell formatting for the date as described above, or use the build short or long date if that style matches your needs.
1Excel counts the number of days since January 0 1900 for the windows version of excel. I believe mac is 1904 or 1905.
The problem is that your date is a text string, so changing the cell number format won't have any effect.
One method of convert the dates in place to "real" dates is to use the Text to Columns wizard.
Select your date(s).
Select the Text to Columns option on the Data Tools Tab of the Data Ribbon:
At Step 1, select "Fixed Width" then "Next"
Step 2 is irrelevant
At Step 3, for the date column, select DMY as the format. You can also select the "Destination" if you want the results written elsewhere.
Then "Finish".
That's it. Your dates will be converted in place
Since your dates are now "real" Excel dates, you can use the Cell ► Number Format dialog to change the format to whatever you want.
Nothing wrong with your format i.e. yyyy/mm/dd. You can use:
=TEXT(A1,"yyyy/mm/dd")
Update
A comment was made on this question re the TEXT function converting a date-serial to text. It will still be possible to apply date functions to the output of the TEXT function and get an output. E.g. here we can see WEEKDAY returning a result on the value of B1 (which in turn is formatting A1):
You are making this way too complicated. Just use the DATE(year,month,day) function and switch the DAY() and YEAR() inside it.
If in cell A1 you have a European-style date in this format: 12-04-2017; Excel will interpret this as Dec 4, 2017.
Excel will interpret it properly as Apr 12, 2017 if you change it to the American-style of 04-22-2017 by writing this equation in another cell: "=DATE(YEAR(A1),DAY(A1),MONTH(A1))".
(I put the DAY() in the month spot and the MONTH() in the day spot.)
Now you can use any date format you want.
I use 'substitute' to replace the '.' with a '/'.
Then use the date format to get the correct format.
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].