jph826
asked on
Diff between hire date and last day of the previous month
CRV10
I need a formula to calculate the number of days between hire date and the last day of the previous month.
For example: If I were to run the report today (May 10), it would count the number of days between hire date and April 30th. No matter when I run the report, the count should always use the last day of whatever the previous month was.
Any assistance would be greatly appreciated. Thanks
I need a formula to calculate the number of days between hire date and the last day of the previous month.
For example: If I were to run the report today (May 10), it would count the number of days between hire date and April 30th. No matter when I run the report, the count should always use the last day of whatever the previous month was.
Any assistance would be greatly appreciated. Thanks
I think dateadd("d",-datepart("d",
Can also do...
Currentdate-{table.hiredat e}-day(Cur rentdate)+ 1
Of course you will get a -ve result if the hire date is in the current month.
Currentdate-{table.hiredat
Of course you will get a -ve result if the hire date is in the current month.
Are you consideriing the hire date as today always?
An easy formula
Day({HireDate})
or using today
Day(CurrentDate)
The number of days from end of last month to today is always the date.
Is that what you want or do you need some other value?
mlmcc
An easy formula
Day({HireDate})
or using today
Day(CurrentDate)
The number of days from end of last month to today is always the date.
Is that what you want or do you need some other value?
mlmcc
ASKER
The hire date could be any date. No matter what the hire date is, or what today's date is, I'm trying to calculate the number of days from the hire date to the last day of the previous month.
For example: employee was hired 3/10/2011 and I'm running the report today. What is the difference between 3/10/2011 and April 30 (the last day of last month).
You've given me something else to think about and that's hire dates this month (May). I understand those will return a negative number which I will just ignore.
Thanks everyone for your help. I'm still struggling with this one.
For example: employee was hired 3/10/2011 and I'm running the report today. What is the difference between 3/10/2011 and April 30 (the last day of last month).
You've given me something else to think about and that's hire dates this month (May). I understand those will return a negative number which I will just ignore.
Thanks everyone for your help. I'm still struggling with this one.
The interval for days is 'd' not dd as above
If you use
ABS(DATEDIFF('d', Formula1, HireDate) )
The value will always be positive.
mlmcc
If you use
ABS(DATEDIFF('d', Formula1, HireDate) )
The value will always be positive.
mlmcc
Last day of last month
DATEADD('d', -1, (DATE(YEAR(TODAY), MONTH(TODAY), 1))
Another alternative
DateAdd('d',-Day(CurrentDa te),Curren tDate)
mlmcc
DATEADD('d', -1, (DATE(YEAR(TODAY), MONTH(TODAY), 1))
Another alternative
DateAdd('d',-Day(CurrentDa
mlmcc
ASKER
Thanks! I need the formula to either ignore the current month and result in nbr of days between hire date and the last day of the previous month - or - the formula needs to show a negative number if the hire date is after the last day of the previous month.
Try
Local DateVar LastDayLastMonth;
LastDayLastMonth := DateAdd('d',-Day(CurrentDa te),Curren tDate);
DATEDIFF('d', HireDate, LastDayLastMonth )
mlmcc
Local DateVar LastDayLastMonth;
LastDayLastMonth := DateAdd('d',-Day(CurrentDa
DATEDIFF('d', HireDate, LastDayLastMonth )
mlmcc
ASKER
Thanks! That returns "a date is required here" and hi-lights the DateAdd('d',-Day(CurrentDa te),Curren tDate);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great - thanks for your help!
Create another formula to take the DATEDIFF between the hire date and your first formula
To get the last day of the month, subtract one day from the first day of this month
Loosely:
DATEADD(dd, -1, (DATE(YEAR(TODAY), MONTH(TODAY), 1))
Formula 2:
DATEDIFF(dd, Formula1, HireDate)