Number of days in between given two dates treating number of days in month as fixed 30 days - excel

I need to calculate difference between two dates with a fixed 30 days a month logic. The example is shown below
Start date = 10/4/2018
End date = 28/10/2018
Expected number of days between = 199
(Excel calculation of difference of days => 28/10/2018 - 10/4/2018 = 201 which is not what I need)
The basis for calculation of difference between two dates is, it should consider number of days in a month as 30 days irrespective of the month. So all months in between the start & end dates with 31 days should be treated as 30 days. If there is Feb in between, it should also be taken as 30 days month.
Procedure to calculate number of days in between two given dates:
Fraction of days in the starting month = 30/4/2018 - 10/4/2018 = 21 days
Months in between 1/5/2018 to 30/9/2018 = 5 months = 5 x 30 = 150 days
Fraction of days in the last month = 28/10/2018 - 1/10/2018 = 28 days
Total days = 21 + 150 + 28 = 199 days.
If A1 is start date cell, B1 = End date cell, please suggest how to do it in excel.

I've broken the formula into the three components as in your example:
The formulas in D2:G2 are:
D2: =IF(AND(YEAR(A2)=YEAR(B2),MONTH(A2)=MONTH(B2)),MIN(DATE(YEAR(A2),MONTH(A2),30),B2),DATE(YEAR(A2),MONTH(A2),30))-MIN(DATE(YEAR(A2),MONTH(A2),30),A2)+1
E2: =MAX(((YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)-1)*30,0)
F2: =MIN(IF(AND(YEAR(B2)=YEAR(A2),MONTH(B2)=MONTH(A2)),0,B2-DATE(YEAR(B2),MONTH(B2),1)+1),30)
G2: =SUM(D2:F2)
or, all in one:
=IF(AND(YEAR(A2)=YEAR(B2),MONTH(A2)=MONTH(B2)),MIN(DATE(YEAR(A2),MONTH(A2),30),B2),DATE(YEAR(A2),MONTH(A2),30))-MIN(DATE(YEAR(A2),MONTH(A2),30),A2)+1+MAX(((YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)-1)*30,0)+MIN(IF(AND(YEAR(B2)=YEAR(A2),MONTH(B2)=MONTH(A2)),0,B2-DATE(YEAR(B2),MONTH(B2),1)+1),30)
I like the elegance of #Jeeped 's code, but this might be easier to follow.

Try this,
=SUMPRODUCT(--(DAY(ROW(INDIRECT(A2&":"&B2)))<>31))+
(DAY(A2)=31)+
SIGN(SUMPRODUCT((MONTH(ROW(INDIRECT(A2&":"&B2)))=2)*(DAY(ROW(INDIRECT(A2&":"&B2)))=28)))*2

It seems to me that your examples are a little "wonky", like how the 31st counts sometimes (like if it's the start/end date) but not others.
Anyway, this function ain't pretty but it does the trick:
Function No31st(startDate As Date, endDate As Date) As Long
Dim d As Date
For d = startDate To endDate 'iterate each day in range
If Day(d) <= 30 Then 'count days up to the 30th
No31st = No31st + 1
'if it's Feb 28, add 2 more days
If (Month(d) = 2 And Day(d) = 28) Then
No31st = No31st + 2 ' + Feb 29 + Feb 30
If Day(d + 1) <> 1 Then d = d + 1 'leap year
End If
End If
Next d
'since the 31st counts if it's the last day:
If Day(startDate) = 31 Or Day(endDate) = 31 Then No31st = No31st + 1
End Function
Sample Output:
StartDate endDate result
10/4/2018 28/10/2018 199
31/1/2018 31/3/2018 61
28/2/2018 1/3/2018 4
28/2/2000 1/3/2000 4
31/1/2018 1/2/2018 2

The DAYS360 formula is based on the 12 30-day month logic.

Simple & Easy Ways:
(1)
=YEARFRAC(start_date,end_date,4)*360
(2)
=DAYS360(start_date,end_date)

Related

Excel Formula caculating number days of year between 2 dates

I am looking for an excel formula to calculating the number of days from years between "Start date" & "end date"
Example :
My start date is 06/19/2020
My end date is 06/20/2023
I would to know on this example the number of days from year 2020 => from start date ; year 2021 (full year) ; year 2022 (full year) ; 2023 => from end date
Result :
number of days of 2020 : 195
number of days of 2021 : 365
number of days of 2022 : 365
number of days of 2023 : 170
in my databse i have different start date and end date by line to x year
Thanks for your help
You can simply substract one cell value from another, if for example:
A1 = TODAY() (which returns today's date)
A2 = 1/01/2019
B1 = A1-A2 = 765 days
Hope it was helpful for you
You might be interested in the DATEDIF function:
https://stackoverflow.com/a/73268311/13406526
Sorry, but I'm a newbie, cannot add comments.

Creating flags for calculating rolling averages in excel

I have a data sheet which looks like:
year month
2017 2017-01
2017 2017-02
2017 2017-03
......
2018 2018-04
2018 2018-05
Note the column month contains text string. I need to create a new column flag in excel which filters which months are to be used in calculating rolling 12M averages for current month and which months are to be used for calculating rolling 12M averages for previous year.
For example today's date is 5/24/2018, so month 2018-05 will be marked as "current". months between 2018-04 to 2017-05 will be marked as "both". month 2017-04 will be marked as "previous". Rest all months will be marked as NA. My final data should look like this:
year month flag
2017 2017-01 NA
2017 2017-02 NA
2017 2017-03 NA
2017 2017-04 Previous
......
2018 2018-04 Both
2018 2018-05 Current
I am having trouble implementing this logic in excel as the column month is a text string and simply using IF condition doesn't works for me. Any leads on this is appreciated.
Edit:
I tried converting the months to a number by using =DATEVALUE(B2 & "-01").
I stored the number for current month in a variable curr.
Now I am using the following formula =IF(B22=curr,"Current", IF(B2=curr-395,"Previous","Both")).
This creates the flag column which I require although there's still an issue based on whether the month has 30 or 31 days. Any solutions for this please?
One way to do it is to use DATDIF.
=DATEVALUE(B2 & "-01") will give you the first of each month in column B.
To return the month number use =DATEDIF(C2,TODAY(),"m") where column C holds the DATEVALUE formula. This will return 0 for this month, 1 for last month... 13 for April 2017.
Now check to see if the count of months = 0 then it's current, if it's greater than 11 it's NA, otherwise it's both. =IF(D2=0,"Current",IF(D2>11,"NA","Both"))
... Edit ....
That's wrong - forgot the "Previous" and "Both" isn't 12 months ....
=IF(D2=0,"Current",IF(D2>13,"NA",IF(D2=13,"Previous","Both")))
As considering your column month format = "YYYY-MM" this code may be helpful
this is Excel function, to use it you need to save this function in the module and use it. `
Function MyDateCal(cell As Range) As String
Dim YearCurrent, YearCell, monthCurrent, MonthCell As Integer
Dim cellVal As String, DiffMonth As Integer[![enter image description here][1]][1]
cellVal = cell.Value
MyDateCal = "NA"
'cellVal = Cells(1, 1).Value
YearCurrent = Year(Now())
monthCurrent = Month(Now())
YearCell = CInt(Left(cellVal, 4))
MonthCell = CInt(Right(cellVal, 2))
DiffMonth = 12 * (YearCurrent - YearCell) + (monthCurrent - MonthCell)
If DiffMonth = 0 Then
MyDateCal = "Current"
ElseIf DiffMonth > 0 And DiffMonth <= 12 Then
MyDateCal = "Both"
ElseIf DiffMonth = 13 Then
MyDateCal = "Previous"
End If
End Function
`

SLA COUNT IN EXCEL FORMULA

I'm looking for an excel (Office 2016 packet) formula that count SLA for ticket resolution.
the SLA counter must consider :
1) Monday To Saturday as work day ;
2) Holiday as no working days (must be skipeed as work day);
3) SLA start for ticket generate in workdays during range-time "08:00-20:00" out of this time-range SLA count is "0" ;
4) Output should result as R1= first 24Hours ; R2= from 25 to 48 hours ; R3= from 49 to 72 hours; "Out of Sla" = since 72 hours
Data to count SLA is formatted as below for either for ticket open and closure:
Column N Column O Column P Column Q
"TICKET START DATE" "TICKET STOP DATE" "SLA" "HOLIDAY"
28/4/18 13:30 30/4/18 19:20 2 25/04/2018
28/4/18 13:11 29/4/18 13:11 1 01/05/2018
28/4/18 12:57 28/4/18 12:57 1
I solved point 1) & 2) with NETWORKDAYS.INTL formula using the first column as start_date ; the second column as end_date; 11 as third formula's field to exclude Sunday as workdays; fourth formula's value pointing a column where are listed the "holidays" date .
I could not find a solution for point 3).
It will also appreciate a possible solution for point 4) .
Thank you in advance.
Formula example of above fields :
=NETWORKDAYS.INTL(N15;O15;11;Q16:Q17)
Alessandro.
I've needed to do something similar in the past. Please see the formula below. It will give you the amount of time between working days (Monday-Friday), only taking into account times 8:30am to 5:30pm. Try inserting your specific parameters.
=IFERROR((NETWORKDAYS.INTL(H8,I8,,)-1)*("17:30"-"8:30")
+IF(NETWORKDAYS.INTL(I8,I8,,),MEDIAN(MOD(I8,1),"8:30","17:30")
,"17:30")-MEDIAN(NETWORKDAYS.INTL(H8,H8,,)*MOD(H8,1),"8:30","17:30"),"")
H8 = Start Date
I8 = End Date
8:30 = Start Time
17:30 = End Time

Set a SUM condition based on DATE calculation in Excel

Problem
I have a table in Excel with a date range and quantities. I need to sum the quantities based date range from today and older then 30, 60, 90, etc days.
Logic
If the product was created within 30 days SUM qty.
If the product was created between 30 days and 60days, SUM qty.
If the product was created between 60 days and 90days, SUM qty.
Expected Results
Qty would equal to 24 (24)
Qty would equal to 32 (12+11+9)
Qty would equal to 26 (10+1+10+5)
Table
CREATED AT QTY
01/02/2016 10
01/02/2016 1
03/02/2016 10
05/02/2016 5
01/03/2016 12
02/03/2016 11
06/03/2016 9
12/03/2016 24
Use SUMIFS():
=SUMIFS(B:B,A:A,"<=" & Today() + 1,A:A,">=" & Today() - 30)
Change the + 1 to -30 and the - 30 to - 60 and so forth.
Or you can set up a small table where you have the end dates listed in a column then you can simply use something like this:
=SUMIFS(B:B,A:A,"<=" & TODAY() - D2 + 31,A:A,">=" & TODAY() - D2)

Derive an End date by Man hours and a start date in Excel-2010

I need a formula which calculates the End Date (with Time) when total Man Hours and Start Date are given. [Excel 2010]
Criteria:
1 Man Day = 8 Hours (1 hour is break time)
Work Start Time = 10:00
Work End Time = 19:00
1 Man Week = Mon - Fri
Holidays, if any, should not be counted
For example:
Cell E7 = Man Hours = 10 Hrs
Cell F7 = Start Date = 26-Jun-15 13:00
Cell G7 = End Date = ???? (Ideally 29-Jun-15 14:00)
*27th and 28th are weekends
Thank you!
margin of error for the estimate of duration from estimate of effort is too big for an hourly granularity to make any sense as long as real people and realistic plans are concerned
however, if we have an estimate of duration in working hours on the input (as opposed to calendar days/weeks/months which are more common units of duration estimates) and we need to calculate the end date-time, we could:
compute helper column with the would-be end hour if there were no closing hours (e.g. in cell H7, in Excel Date units = fractions of a day)
=MOD(F7, 1) + MOD(E7, 8)/24
check if the would-be hour is before the closing hours and adjust the end day + end time accordingly. If it's after, move to the next workday and adjust time, e.g. for simplicity assume all breaks are at the beginning of a day, so we can subtract the number of hours in a workday:
=IF(H7 <= 19/24,
WORKDAY(F7, E7/8, holidays) + H7,
WORKDAY(F7, E7/8 + 1, holidays) + H7 - 8/24)
assume you saved your national holidays on column I, you can try below in cell H7:
=IF(HOUR(F7+E7/24)>19,((F7+E7/24)-INT(F7+E7/24)-0.792)+(WORKDAY(F7,1,I:I))+0.417,F7+E7/24)

Resources