Count number of day based on entry and leaving date (per month)

sastoka

Board Regular
Joined
Jun 14, 2014
Messages
193
Hi there,

I'm facing an issue and i don't even know if it's possible to fix.


Context:

I'm calculating allowances. The amount is per paid day, so I need to know how many days each employee has been in a country.

While I know the total number of days. it's supposed to be a salary so I need to break it down per month.


Need:

I would like some formula that auto populate the number of days depending on the entry and leaving date.


Difficulties:

Since I work with salary I assume that each month has 30 days (make it easier for calculation) so that's an added difficulty (Maybe)

Also it needs to take into account that when it's about entry, the entry day must be counted as a day in the country.

I know how to do that with a vba but the save location doesn't support macro file.


Example:

I've included a picture (can't poste proper table currently) of the expected result in 3 different situations.

tempo.jpg


Thanks in advance to those who take the time to read and think about it.

If you need more info let me know. And if i'm not clear, i'm sorry.

Regards,

Sastoka.

PS: I'm using Excel 2013.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
if salary is $35000 per year and in January 21days in the country amount = 35000/365.25*21

entry date 3/1/16
leaving date 23/1/16
days = 23/1/16 - 3/1/16 + 1


for your first example

=((15/10/16-6/1/16)+1)/365.25 * yearly salary
 
Upvote 0
Hi Oldbrewer,

Thanks for this, but I would like each month to auto update.

Basicaly i want to enter an entry date and a leaving date

and the month below to be calculated.


Thanks.
 
Upvote 0
This might work for you:


Excel 2016 (Windows) 32 bit
ABCDEFGH
1Example 1Example 2Example 2
2
3Entry Date06/01/2016Entry Date14/05/2016Entry Date01/02/2016
4Leaving Date15/10/2016Leaving Date30/09/2016Leaving Date01/07/2016
5
6MonthNumber of day in the countryMonthNumber of day in the countryMonthNumber of day in the country
7January25January0January0
8February30February0February30
9March30March0March30
10April30April0April30
11May30May17May30
12June30June30June30
13July30July30July1
14August30August30August0
15September30September30September0
16October15October0October0
17November0November0November0
18December0December0December0
Sheet1
Cell Formulas
RangeFormula
A7=DATE(YEAR(B$3),ROWS($7:7),1)
B7=MAX(MIN(B$4,DATE(YEAR(A7),MONTH(A7),30))-MAX(B$3,A7)+1,0)
D7=DATE(YEAR(E$3),ROWS($7:7),1)
E7=MAX(MIN(E$4,DATE(YEAR(D7),MONTH(D7),30))-MAX(E$3,D7)+1,0)
G7=DATE(YEAR(H$3),ROWS($7:7),1)
H7=MAX(MIN(H$4,DATE(YEAR(G7),MONTH(G7),30))-MAX(H$3,G7)+1,0)


WBD
 
Upvote 0
Try this. It checks for leap year and uses the actual last day of a given month

Code:
=IF(OR(MONTH($B$1)>MONTH(DATEVALUE($A5&" 1")),MONTH($B$2)<MONTH(DATEVALUE($A5&" 1"))),0,IF(MONTH($B$1)=MONTH(DATEVALUE($A5&" 1")),IF(OR(MOD(YEAR($B$1),400)=0,AND(MOD(YEAR($B$1),4)=0,MOD(YEAR($B$1),100)<>0)),SUM(CHOOSE(MONTH(DATEVALUE($A5&" 1")),31,29,31,30,31,30,31,31,30,31,30,31)-DAY($B$1)),SUM(CHOOSE(MONTH(DATEVALUE($A5&" 1")),31,28,31,30,31,30,31,31,30,31,30,31)-DAY($B$1))),IF(MONTH($B$2)=MONTH(DATEVALUE($A5&" 1")),IF(OR(MOD(YEAR($B$1),400)=0,AND(MOD(YEAR($B$1),4)=0,MOD(YEAR($B$1),100)<>0)),SUM(CHOOSE(MONTH(DATEVALUE($A5&" 1")),31,29,31,30,31,30,31,31,30,31,30,31)-DAY($B$2)),SUM(CHOOSE(MONTH(DATEVALUE($A5&" 1")),31,28,31,30,31,30,31,31,30,31,30,31)-DAY($B$2))),IF(OR(MOD(YEAR($B$1),400)=0,AND(MOD(YEAR($B$1),4)=0,MOD(YEAR($B$1),100)<>0)),CHOOSE(MONTH(DATEVALUE($A5&" 1")),31,29,31,30,31,30,31,31,30,31,30,31,CHOOSE(MONTH(DATEVALUE($A5&" 1")),31,29,31,30,31,30,31,31,30,31,30,31))))))
 
Upvote 0
Sorry missed the criteria that you assume every month is 30 days

try this: just insert the formula in the cell to the right of the month


Code:
=IF(OR(MONTH($B$1) > MONTH(DATEVALUE($A5&" 1")),MONTH($B$2) < MONTH(DATEVALUE($A5&" 1"))),0,IF(MONTH($B$1)=MONTH(DATEVALUE($A5&" 1")),SUM(30-DAY($B$1)),IF(MONTH($B$2)=MONTH(DATEVALUE($A5&" 1")),SUM(30-DAY($B$2)),30)))
 
Last edited:
Upvote 0
@RCBricker,

unfortunately, the formula doesn't work it return, #VALUE, as it can't calculate the formula MONTH.

@wideboydixon,
yours worked like a charm, it did exactl what i asked.

thanks a lot.

Thanks all.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top