excel formula: end date - todays date plus another variable - excel

i need an excel formula to calculate the total days remaining for a cell: end date minus todays date plus extension days(maybe 30-90 amount is in a cell) i have tried =days360(today's date,end date + number of extension days) in a different cell but it isn't giving me the correct total
It's giving me the wrong amount of days. I have a formula calculating my end date as well, is that causing a problem =SUM(start date+90+#of extension days)

One possible reason could be your usage of the DAYS360 formula. That uses a 360-day calendar and assumes all months are 30 days. Therefore if you are covering a range where this would have an effect, you will see a difference. For example, with the range 1/1/2013 to 6/1/2013, subtracting the two dates returns 31+28+31+30+31 = 151, compared to DAYS360, which returns 30*5 = 150.
Try just doing basic subtraction, which will also work on dates:
=<End Date> - TODAY() + <Extension>

Related

Excel - count days in each month between two dates (both dates available)

I have found the solution thought it would be good to share:
so the formula should be :
=((MAX(CT$6-$N8,0)-MAX(EOMONTH(CT$6,-1)-$N8,0))-(MAX(CT$6-$O8,0)-MAX(EOMONTH(CT$6,-1)-$O8,0))+(EOMONTH(CT$6,0)=EOMONTH($N8,0)))*1
:)
I am trying to write an excel formula which can be dragged across a row of cells to give the number of days in each month between two specified dates. E.g:
I tried using a if with sum product formula from the same website but for some reason it is not recognising the days of last month. was wondering if someone could help explain what this formula does and how to correct it.
=IFERROR(IF(AND(CS$6>=$M9,CS$6<=$N9),SUMPRODUCT(--(MONTH(ROW(INDIRECT($M9&":"&IF($N9="",TODAY(),$N9))))=MONTH(CS$6))),),"")
SECOND REVISION (R2)
Updated workbook link to capture fixed column headings
Eqn / formula also includes static view
Depending upon years spanned, R2 represents a less favourable outcome re space (will require more columns). In this case, number of additional columns required to match stacked view ~100 (!!).
FIRST REVISION (R1) etc. based upon #Charlotte.Sarah.Smith feedback
Days in each month were 1 day less than they should have been - this has been corrected (in both screenshot, linked sheet, and relevant eqns)
Also showcase a couple of sample illustrations/visual representations which may/not be of interest (included within linked sheet too)
Suppose we wanted to expand upon #Will's solution by stacking the dates by year, so that column headings can vary according to different start dates (as opposed to the very first start date that happens to appear)...
For instance, if the next row included the date range 'start = 10/02/16' through 'end = 15/03/19' - you'll appreciate that the number of columns spanning Jan-Dec ('16), Jan-Dec ('17),... up to (and incl.) the range in the first row (Jan '21 - Mar '23) becomes unwieldy.
By using a data table (see here) you can produce a 'stacked' view of the number of days per month regardless of the year (!) - see screenshot below and link to this [updated/corrected] worksheet.
R2 screenshot:
REVISION
See validation/reconciliation column at end
*Visual representations - could be useful for assessing trends etc.
Fun in 3D too!
1] Red font: first row that defines the construct of the data table: enter date range in the format '10/02/2021-15/08/2023'
Cell E3 eqn (drag to right):
=IFERROR(IF($A3>EDATE(E$2,1),0,MAX(,IFERROR(IF(MIN($B3,MIN(EDATE(E$2,1),$B3))=E$2-1,0,MIN($B3,MIN(EDATE(E$2,1),$B3))),"")-MAX($A3,E$2))),0)
(Similar to what we've seen previously)
2] Table below red font: enter any start date (as a regular date, e.g. dd/mm/yyyy) < end date (likewise, regular date) in columns A, B as desired/req.
Data Table
3] Data Table (column data): enter the following in cell c4 (drag down as req.)
=TEXT(A4,"dd/mm/yyyy")&"-"&TEXT(B4,"dd/mm/yyyy")
4] Data Table (highlight cells c3:d42, insert data table, select blank/empty cell for 'row input' and c2 for 'column input')
The data table should 'come to life' (calculate sheet, shift + F9) otherwise.
FilterXML
5] Split result by delimiter '|' using FilterXML as follows (cell E4, only drag down, not to right):
=IFERROR(TRANSPOSE(FILTERXML("<AllText><Num>"&SUBSTITUTE(LEFT(MID(D4,2,LEN(D4)-1),LEN(MID(D4,2,LEN(D4)-1))-1),"|","</Num><Num>")&"</Num></AllText>","//Num")),"")
VALIDATION
Note the check column: date difference = sum of days in table (default cell colour is otherwise RED):
REVISION 2
Here is the formula for a static version of above (i.e. no stacking by year, instead, each date in column headers are distinct re calcs) - it was already available in row with red font(!!)
=IFERROR(IF($A3>EDATE(C$2,1),0,MAX(,IFERROR(IF(MIN($B3,MIN(EDATE(C$2,1),$B3))=C$2-1,0,MIN($B3,MIN(EDATE(C$2,1),$B3))),"")-MAX($A3,C$2))),0)
Viola!
One potential solution would be to compare dates using the MIN and MAX functions like this:
=IF(MIN($B2+1,D$1)-MAX($A2,C$1)<0,"",MIN($B2+1,D$1)-MAX($A2,C$1))
screenshot
This solution uses month starting dates (e.g., Feb 1, 2021), but it could be adapted to work with month end dates instead (e.g., Feb 28, 2021).
The idea is that you take the later of the finish date or month end date minus the lesser of the start date or the month start date. For the first month and last months, this returns the number of days within that range inclusive of the first and last day. For all the months between the first and last months, it returns the number of days in the month.
The +1 on the minimum of the end dates seems a little counterintuitive, but it's necessary to include the first and last day in the count. Without it, you'd get 14 days in March 2022 instead of 15.
The "if less than zero" function makes it return a blank (or zero if you'd prefer) for any month outside the dat range.
This solution does not summarize by month (e.g., 19 days for Feb 2021 plus 28 days for 2022 to get 47 total days in February), but that's consistent with the sample you provided. The comments also indicate that you want to consider the years as well.

dd.mm.yyyy hh:mm incrementing by half hour in vba

I have got a start date and end date in this custom format
dd.mm.yyyy hh:mm in excel cells.
What i need is to fill specific row with dates incremented by half hour from start date to end date using VBA code. And i havent got any idea how to do this.
On web there are some examples with similar problems but with only months or only hours and those are dates format not custom.
You can do this with a simple formula.
Write your start date into cell A1
In A2 write =A1+(1/48)
Copy formula from A2 down
done.
How does this work?
Excel dates are represented as count of days since 1900. That means 1900-01-01 is the first day and represented by 1. All other dates are just the count of days since then. 1 represents one day. So since 1 day has 24 hours 1/48 represents half an hour.
The number format dd.mm.yyyy hh:mm how Excel shows the date is not relevant, because Excel only saves the value (amount of days since 1900) in the cell value.
So if you type the date of today into a cell 2018-10-11 Excel actually saves 43384 in the cell value (today it is 43384ᵗʰ day since 1900-01-01).
One option is to find the interval between start and stop point. Remember that excel dates that are actually dates and not strings are actually integers. The second thing to remember is time is the decimal part which represent fraction of a day. Test if your date (assuming it's in A1) is an actual date or a string with
=ISNUMBER(A1)
If that comes back TRUE you do not need to worry about converting your date. If it comes back FALSE, its actually a string and will need to be converted for excel to work with it.
Divide this interval by 30 minutes, or 30/60/24 to and add 1. This will tell you how many iteration you will need which you can put into a For loop
Start_Number = Range("A1")
End_number = Range(("A2")
Stamp = Start_Number
Interval_number = End_Number - Start_Number
Counter = integer of (Interval_number / (30/60/24))
For x = 1 to counter
write Stamp to cell
Stamp = Stamp + 30/60/24
Next x
Allternatively you could set up a while loop.
Do While datetime < Stop_Point
Write datetime to cell
Datetime=datetime + 30/60/24
Loop
Please note, not actual code but giving idea where OP had no idea where to start.

Calculating exact fraction of months during period

I have a list of periods (given by period start, period end) in Excel and I have to calculate exactly how many months (as a fraction) are during that period.
E.g. if given a period January 15th to March 7th, then this would be
15-01-2015 until 31-01-2015 = 17 days
01-02-2015 until 28-02-2015 = 28 days
01-03-2015 until 07-03-2015 = 7 days
Months during period = 17/31 + 28/28 + 7/31 = 1,774193548 months
Note that in this calculation, start date and end date are both counted as part of the period.
As the periods can be anything, then I haven't been able to figure out to calculate this with an Excel formula (or if it's even possible).
Any ideas?
Well it's not pretty, but if you have a start date at A1 and an end date at A2, then:
=12*(YEAR(A2)-YEAR(A1))+MONTH(A2)-MONTH(A1) +
(DAY(A2)/(DATE(YEAR(A2),MONTH(A2)+1,1)-DATE(YEAR(A2),MONTH(A2),1))) -
((DAY(A1)-1)/(DATE(YEAR(A1),MONTH(A1)+1,1)-DATE(YEAR(A1),MONTH(A1),1)))
The way this works is:
12*(YEAR(A2)-YEAR(A1)): Difference in year times 12.
+MONTH(A2)-MONTH(A1): (plus) Difference in months.
+(DAY(A2)/(DATE(YEAR(A2),MONTH(A2)+1,1)-DATE(YEAR(A2),MONTH(A2),1))): (plus) Day of end date divided by the total days in end month, calculated by the diff between that month's 1st and the following month's 1st.
-((DAY(A1)-1)/(DATE(YEAR(A1),MONTH(A1)+1,1)-DATE(YEAR(A1),MONTH(A1),1))) (minues) Day of start (minus 1 to not count that day) month divided by the total days in start month.
Of course you duplicate that for any set of cells...
Assuming column A lists the start dates and column B lists the end dates:
=SUMPRODUCT((1+B1:B3-A1:A3)/DAY(DATE(YEAR(A1:A3),MONTH(A1:A3)+1,)))
Note: you will need to increase the depth of the ranges to suit your needs... just change the 3s to a deeper row number.
UPDATE
Based upon your feedback and new requirement, here is a version of the above formula that will calculate the total, one row at a time:
=(1+B1-A1)/DAY(DATE(YEAR(A1),MONTH(A1)+1,))
UPDATE 2
Based on new information that the interval on one row can exceed one month, here is a new version of the formula:
=DATEDIF(A1-DAY(A1)+1,B1,"m")-1+(1+EOMONTH(A1,0)-A1)/DAY(DATE(YEAR(A1),MONTH(A1)+1,))+(B1-EOMONTH(B1,-1))/DAY(DATE(YEAR(B1),MONTH(B1)+1,))
IMPORTANT NOTE: After confirming this formula you will need to apply GENERAL number formatting to the cell. This is because Excel will try to apply DATE number formatting unnecessarily.
Why don't you use:
=12*YEARFRAC(StartDate,EndDate)

Check if any date within a range is within 1 month of todays date

I've got a column full of dates. How can I check that column to find which date is within a month of todays date, and then return it?
If there is no date within a month, just return blank
Lets say my dates are:
01-Jan-12
01-Apr-12
01-Jul-12
01-Oct-12
01-Jan-13
The code im using is below. A:A is the range of the dates above
=MIN(IF(A:A>TODAY(),A:A))
The issue im having is that if I use the above, it returns 01/01/12 and not 01/01/13. Also, if I change the dates so the next date is December 1st 2012, it still returns 01/01/12
So you really just want the earliest date if that's within a month? If so perhaps try
=IF(MIN(A:A)-TODAY()<=30,MIN(A:A),"")
Assumes dates in column A
If you have past and future dates try this formula
=IFERROR(SMALL(IF(A2:A100>=TODAY(),IF(A2:A100<=TODAY()+30,A2:A100)),1),"")
confirmed with CTRL+SHIFT+ENTER
or for exactly 1 month (rather than 30 days) try using EDATE, i.e.
=IFERROR(SMALL(IF(A2:A100>=TODAY(),IF(A2:A100<=EDATE(TODAY(),1),A2:A100)),1),"")

Convert an Excel formula to an Access query

Is there a way to convert the below Excel formula to a query/criterion in Access?
L2 = Date
J2 = Another Date
Z1 = Todays Date
I think it is calculating the number of days in between two dates but not sure how to do this in an Access query.
IF((AND((L2<1),(J2>1))),(NETWORKDAYS(J2,$Z$1)-1),0)
As you may by now have gathered, the question does not really make sense. NETWORKDAYS does indeed calculate the number of “whole working days excluding weekends and any dates identified in holidays” between two dates (here whatever date is in J2 and whatever is ‘Today’/Z1) and IF makes that calculation contingent upon the result of the AND function being TRUE. The AND function results in TRUE provided both the ‘date’ in L2 is before 1/1/1900 and the date in J2 is after 1/1/1900 (because to Excel 1/1/1900 is Day 1 where dates are concerned [unless one opts for the 1904 date system]).
But Excel does not recognise a date before Day 1, whether a negative number or a decimal number. For example Day 1.5 is noon on 1/1/1900 whereas in the same format Day 0.5 shows as 0/1/1900.
So in essence, L2 is not a date of any real use to the formula, hence I believe why no answer yet to your question. But this is too long to fit in a comment hence my answer: “No.”!
Set a reference to Excel.
Option Compare Database
Private Sub Command2_Click()
MsgBox GetNetWorkDays(#1/29/2017#, #2/8/2017#)
End Sub
Function GetNetWorkDays(startDate As Date, endDate As Date) As Integer
GetNetWorkDays = WorksheetFunction.NETWORKDAYS(startDate, endDate)
End Function
Put the button on a Form and click the button!
If you want to calculate number of days between days than you can use below built in function "DateDiff" which will solve it out. Datediff("D",,)
Ex. Datediff("D",L2,Z1)

Resources