Have a few different items with different rental periods ( 1,3,6 months to 1,3,5 years). As it stands I have a column with the last renewal date and a column indicating what is the renewal period. I wanted excel to calculate what the Renewal date would be based on the selected type of renewal. My first attempt was to convert the renewal types to some kinda of similar denomination but i got stuck trying to figure out what value/format to use.
Last renewal date Renewal Type Renewal Date
11/11/2013 1 Year
2/14/2014 2 Years
8/28/2011 5 Years
11/27/2013 3 Months
[Excel stores dates as floating point numbers. They advance by 1 each day and the fractional part holds the day fraction, e.g. 0.5 is midday. The exact value is user-configurable between 1900 and 1904 origins which can complicate things. Note that in the 1900 origin, date 60 (corresponding to the non-existent date 29-Feb-1900) is defined. Leap seconds are not implemented.]
If you can tolerate the second column being integral months, then use the EDATE function.
For example, if your table is orientated on cell A1, use
=EDATE(A2, B2) in cell C2 and copy downwards.
I would use a Vlookup in the third column which should point to a table which has conversion of 1 year/6mos into days. (365,180, ect). Then just add that vlookup to the original date.
So
`TblDate
Lookup Days
1mo 30
.. ..`
=VLOOKUP(B1,TblDate,2,FALSE)+A1
Maybe try:
=IF(ISERROR(FIND("year",B2)),DATE(YEAR(A2),MONTH(A2)+LEFT(B2,1),DAY(A2)),DATE(YEAR(A2)+LEFT(B2,1),MONTH(A2),DAY(A2)))
In D2 enter:
=--MID(B2,1,FIND(" ",B2))
and copy down
In E2 enter:
=MID(B2,FIND(" ",B2)+1,1)
and copy down
Finally in C2 enter:
=IF(E2="Y",DATE(YEAR(A2)+D2,MONTH(A2),DAY(A2)),DATE(YEAR(A2),MONTH(A2)+D2,DAY(A2)))
Format C2 as Date and copy down. For example:
.
.
There is a way to convert your second column into pure month format, using Excel:
=IF(COUNTIF(B2,"*Year*"),(TRIM(LEFT(B2,2)))*12,IF(COUNTIF(B2,"*Month*"),TRIM(LEFT(B2,2)),NA()))
This can then be used with EDATE(). For example, lets say that the above code is in cell C2, it would produce 12. Then, you could in cell D2, you could put
EDATE(A2,C2)
in there. The code works for anything between 1 month and 99 years and doesn't care whether the first number is one or two digits and whether the word is month, months, year or years - it will work with all of it, as TRIM() removes whitespace (thus allowing for one character and a space or two characters) and * is a wildcard (hence allowing x years or xz year).
For EDATE to work you need to make sure the number format is set to date type.
Note: an extra cell for the months will be needed - so it might require a little rearranging, but using CTRL+C or copy cells tool in the bottom right of a selected cell will easily copy it, and for each one it will automatically convert it.
create a new column and type in the formaula box
=B2+1095
to get your renewal date
1 year is 365
2 years is 730
3 years is 1095
and so on and so forth.
this was the most simple way and worked for me!
Related
I have a excel spreadsheet with two columns. One with a date and another with the value.
I want to get the working day of the month with the lowest value.
I tried to use a pivot table for it and then group the date but I get a lot of errors.
You can find the spreadsheet here and the sheet name is Historical. The others are just attempts made by me.
Spreadsheet
Thanks
The formula entered in E2 below
is
=AGGREGATE(15,6,(POWER(10,LOG10(((YEAR(D2)=YEAR($A$2:$A$3254))*(MONTH(D2)=MONTH($A$2:$A$3254)))))*$B$2:$B$3254),1)
and the array formula entered in F2 below is
=INDEX($A$2:$A$3254,MATCH(YEAR(D2)&MONTH(D2)&E2,YEAR($A$2:$A$3254)&MONTH($A$2:$A$3254)&$B$2:$B$3254,0))
I suggest to make an triple nested if-construct that checks if the weekday of the date is a workday, or the date+ 1 or the day +2. Assuming the date is in cell A4
= if(instr(weekday(A4),”23456”)>0, A4,
if(instr(weekday(A4+1),”23456”)>0, A4 + 1,
if(instr(weekday(A4+2),”23456”)>0, A4 + 2,”cannot happen”)))
Explanation: one of 3 consecutive days is always a working day.
There may be typos since I edit that on iPad without Excel available to test.
Weekday returns 1 for Sunday and 7 for Saturday. So 2-6 are workdays.
However with that simple approach you will not detect public holidays on a working day if that is a problem.
Hope I understood you question correctly. One data example with solution would have explained it better.
I have a cell G4 with date and time in a format (Text string):
1/29/2020 1:34:24 PM
I need to convert it to DATE formatted cell. How to do that?
I have tried to get numbers and convert them to DATE with this formula:
=DATE((MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2));(MID(G4;SEARCH("/";G4)+1;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)-1));(LEFT(G4;FIND("/";G4;1)-1)))
So:
I am extracting year:
=MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2)
Month
=MID(G4;SEARCH("/";G4)+1;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)-1)
Day
=LEFT(G4;FIND("/";G4;1)-1)
I am getting as a result:
1.5.2022
I need it as it is now, but output should be 29.1.2020 in this case. Later I want to get day difference two that way formatted dates. Is it possible to do it with formula without performing any other cell formatting operations?
EDIT:
I got it working, the only problem is:
How to extract number (year) after third "/"? My current formula is not correct:
=MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2)
It does not function correct in this case:
2/5/2020 12:21:05 PM
EDIT:
I did it this way (I also had to minus G2 - F2, to get days difference):
=IFERROR(DAYS(MID(G2;SEARCH("/";G2)+1;SEARCH("/";G2;SEARCH("/";G2)+1)-SEARCH("/";G2)-1)&"."&LEFT(G2;FIND("/";G2;1)-1)&"."&MID(G2;FIND("/";G2;FIND("/";G2)+1)+1;4);MID(F2;SEARCH("/";F2)+1;SEARCH("/";F2;SEARCH("/";F2)+1)-SEARCH("/";F2)-1)&"."&LEFT(F2;FIND("/";F2;1)-1)&"."&MID(F2;FIND("/";F2;FIND("/";F2)+1)+1;4));"")
You probably need to replace an order of day.month.year and "." to "/" if you are using different date setting (region). I have one setup, so this seems to work.
FYI DATES in excel are stored as integers. They represent the number of days since 1900/01/01 with that date being 1. TIME is stored as a decimal representing fractions of a day or 24 hours. 0.5 represents noon. 24:00 is not an officially supported time in excel, but will work with some functions.
The DATE Formula is looking for three arguments representing YEAR, MONTH, DAY in that order.
DATE(Year, Month, Day)
You need to pull the text from your string representing these values. I find it easiest to pull each one individually in its own cell to ensure the part of the formula is working first then copy and past that part into the DATE formula so the whole calculation in the end can be performed in one cell.
YEAR
To get the year use the following formula:
MID(G4,FIND("/",G4,FIND("/",G4)+1)+1,4)
MONTH
To get the month use the following formula:
LEFT(G4,FIND("/",G4)-1)
DAY
To get the day use the following formula:
MID(G4,FIND("/",G4)+1,FIND("/",G4,FIND("/",G4)+1)-FIND("/",G4)
COMBINED FORMULA
Place the above formulas into the date formula as follows:
=DATE(MID(G4,FIND("/",G4,FIND("/",G4)+1)+1,4),LEFT(G4,FIND("/",G4)-1),MID(G4,FIND("/",G4)+1,FIND("/",G4,FIND("/",G4)+1)-FIND("/",G4)-1))
Note the only cell reference in the formula is G4. The results of the formula are not in an Excel Date format. Change the formatting of your cell to meet your needs. In your case I would apply a custom cell format of d.m.yyyy
If you have TEXTJOIN,
=TEXTJOIN("/",TRUE,INDEX(FILTERXML("<a>,<b>"&SUBSTITUTE(SUBSTITUTE(TEXT(A1,"dd/mm/yyyy hh:mm:ss"),"/","</b><b>")," ","</b>",1)&"</a>","//b"),N(IF({1},{2,1,3}))))
Depending on your version it may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
the reason the second did not work is that Excel actually changed it to a date and a date is a double, not text. So there are no / in the data. so we need to force back to the incorrect string.
Those for whom the TEXTJOIN function is not available can use this:
=DATE(FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[3]");FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[1]");FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[2]"))
I have two columns of year in excel sheet as year.months format (column first as 1.11 means 1 year 11 months) column second as 0.7 means 7 months). I need difference between two columns as year.months format. i.e., 1.11-0.7=1.4 means 1 year 4 months.
This approach will perform the math by converting everything to the same base units as month. You can perform the steps over multiple column which will make it easier to read, maintain and troubleshoot. When everything is working you can combine it into a single formula which will be a monstrosity that is hard to read and potentially maintain by others in the future.
For the sake of this solution, assume your 1.11 date is in A1 and you 0.7 date is in B1.
Step 1) Convert A1 and B1 to months
In C1 place the following formula and copy it to D1
=LEFT(A1,FIND(".",A1)-1)*12+RIGHT(A1,LEN(A1)-FIND(".",A1))
Step 2) Find the difference in months
In E1 Place the following formula
=C1-D1
Step 3) Convert difference in months back in to year.month format
In F1 place the following formula
=INT(E1/12)&"."&(E1-INT(E1/12)*12)
Now if you got and substitute formulas into one another so its all in a single cell, your formula will wind up looking the following.
=INT(((LEFT(A1,FIND(".",A1)-1)*12+RIGHT(A1,LEN(A1)-FIND(".",A1)))-(LEFT(B1,FIND(".",B1)-1)*12+RIGHT(B1,LEN(B1)-FIND(".",B1))))/12)&"."&(((LEFT(A1,FIND(".",A1)-1)*12+RIGHT(A1,LEN(A1)-FIND(".",A1)))-(LEFT(B1,FIND(".",B1)-1)*12+RIGHT(B1,LEN(B1)-FIND(".",B1))))-INT(((LEFT(A1,FIND(".",A1)-1)*12+RIGHT(A1,LEN(A1)-FIND(".",A1)))-(LEFT(B1,FIND(".",B1)-1)*12+RIGHT(B1,LEN(B1)-FIND(".",B1))))/12)*12)
I would not want to be someone new coming in and looking at that and trying to figure out what its doing let alone editing it 3 months down the road when a change is required.
A few caveats, Make sure the date in A is bigger than the date in B. It gives bad results for negative values. Also ensure there is always a "." in the date or errors will ensue. If there is a 12 month difference it will currently display 1.0 as the difference instead of 0.12. If the later is required, a special case would need to be developed for when there is differences resulting in multiples of 12 differences.
Working with DatedIF
Assume start date is in B1 and end date is in A1.
Step 1) Convert date
Convert the string to an actual excel serial date
In C1 and Use the following formula and copy to D1
=DATE(LEFT(A1,FIND(".",A1)-1),RIGHT(A1,LEN(A1)-FIND(".",A1)),1)
The conversion assumes the first of the month
Step 2) Determine the difference in months
Place the following in E1
=DATEDIF(D1,C1,"M")
Note the start date need to be further back in time than the end date or you will get #NUM error.
Step 3) Convert back to your string format for y.m
Place the following in F1
=INT(E1/12)&"."&(E1-INT(E1/12)*12)
and combined into the uglyness of a single cell formula:
=INT((DATEDIF(DATE(LEFT(B1,FIND(".",B1)-1),RIGHT(B1,LEN(B1)-FIND(".",B1)),1),DATE(LEFT(A1,FIND(".",A1)-1),RIGHT(A1,LEN(A1)-FIND(".",A1)),1),"M"))/12)&"."&((DATEDIF(DATE(LEFT(B1,FIND(".",B1)-1),RIGHT(B1,LEN(B1)-FIND(".",B1)),1),DATE(LEFT(A1,FIND(".",A1)-1),RIGHT(A1,LEN(A1)-FIND(".",A1)),1),"M"))-INT((DATEDIF(DATE(LEFT(B1,FIND(".",B1)-1),RIGHT(B1,LEN(B1)-FIND(".",B1)),1),DATE(LEFT(A1,FIND(".",A1)-1),RIGHT(A1,LEN(A1)-FIND(".",A1)),1),"M"))/12)*12)
Let's say A1=1.11 and B1=0.7 then formula would be:
=LEFT(A1;FIND(".";A1;1)-1)-LEFT(B1;FIND(".";B1;1)-1)&"."&(MID(A1;FIND(".";A1;1)+1;2)-MID(B1;FIND(".";B1;1)+1;2))
I need to write some code that compares dates in an excel file and then high lights those rows of data based on the data evaluations. Essentially there are 3 columns in this file that have a standard Month/day/year format. I need to compare the day of all three columns to see if they are within a 3 day date difference "don't care about the month". If they are not within the 3 day date difference I want to high light them. An example of an OK comparison would be (10/1/2015,12/2/2015, 8/3/2015) I would not want to do anything with this row of data. Here is what I consider to be a "bad" date comparison (10/1/15, 11/3/2015, 8/5/2015). All the dates have to be within 3 days and as you can see there is a 4 day date difference between 10/1 and 8/5. How can I write something up like this to evaluate this?
You can just compare the Max() of the days to the Min() of the days with the Array Formula:
=IF(MAX(DAY(A1:C1))-MIN(DAY(A1:C1))>3,"fail","Close enough")
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
You can do the same functionality with VBA if that is needed.
So I have a cell with 7/6/2012 10:26:42 inputted, I want to show the date difference from today in another cell.
I tried to extract 7/6/2012 with =LEFT(A1, Find(" ", A1, 1) -1) but turned out theres a value error.
The formula works when I make A1 '7/6/2012 10:26:42, however it is not ideal because I have to work with the whole column.
You can use the datedif function to find out difference in days.
=DATEDIF(A1,TODAY(),"d")
Quote from excel.datedif.com
The mysterious datedif function in Microsoft Excel
The Datedif function is used to calculate interval between two dates in days, months or years.
This function is available in all versions of Excel but is not documented. It is not even listed in the "Insert Function" dialog box.
Hence it must be typed manually in the formula box.
Syntax
DATEDIF( start_date, end_date, interval_unit )
start_date from date
end_date to date (must be after start_date)
interval_unit Unit to be used for output interval
Values for interval_unit
interval_unit Description
D Number of days
M Number of complete months
Y Number of complete years
YD Number of days excluding years
MD Number of days excluding months and years
YM Number of months excluding years
Errors
Error Description
#NUM! The end_date is later than (greater than) the start_date
or interval_unit has an invalid value.
#VALUE! end_date or start_date is invalid.
If that's a valid date/time entry then excel simply stores it as a number (days are integers and the time is the decimal part) so you can do a simple subtraction.
I'm not sure if 7/6 is 7th June or 6th July, assuming the latter then it's a future date so you can get the difference in days with
=INT(A1-TODAY())
Make sure you format result cell as general or number (not date)
For the difference between A1 and Today's date you could enter:
=ABS(TODAY()-A1)
which returns the (fractional) number of days between the dates.
You're likely getting a #VALUE! error in your formula because Excel treats dates as numbers.
DAYS(start_date,end_date):
For example:
DAYS(A1,TODAY())
Why don't you just make it easy and simple. If I need to know the number of days between today and say, March 10th, 2015, I can just enter the simple formula.
Lets say the static date is March 10th, 2015, and is in cell O5.
The formula to determine the number of days between today and O5 would be, =O5-Today()
Nothing fancy or DATEDIF stuff. Obviously, the cell where you type this formula in must have a data type of 'number'. Just type your date in normally in the reference cell, in this case O5.
=ROUND((TODAY()-A1)/365,0) will provide number of years between date in cell A1 and today's date
*In all instances the # refers to the cell number
You really don't need the datedif functions; for example:
I'm working on a spreadsheet that tracks benefit eligibility for employees.
I have their hire dates in the "A" column and in column B is =(TODAY()-A#)
And you just format the cell to display a general number instead of date.
It also works very easily the other way: I also converted that number into showing when the actual date is that they get their benefits instead of how many days are left, and that is simply
=(90-B#)+TODAY()
Just make sure you're formatting cells as general numbers or dates accordingly.
Hope this helps.