### Post

3 followers Follow # Calculation field duration two dates

Looking to try to create a calculation field for days vacant for rental properties.  I have a move out date and move in date field- I want it to calculate even if there is not a "move in date" put in.  For example, if someone moves out on 11/20/18, I want it to calculate the days vacant based on today's date UNLESS a move in date is put in.  I have this so far, but I'm stuck.

var start = moment(@Move Out Date);
var end = moment(@Move In Date);
var diffMS = end.diff(start) // difference in milliseconds;
var diffDur = moment.duration(diffMS);
var diffDays = diffDur.asDays();
diffDays

Jon Smith To calculate from the day of the move until today, try this:

Field Name: Days Vacant (calculation field)

Math.floor((Date.now() - @Move out date) / 86400000)

Unit: Days

To calculate how much days was the the  properties ocuped (with move in and move out date fields)

Math.floor((@Move Out - @Move In) / 86400000) + 1

Unit: Days That will return a correct result for the day you create the calculation or for the day you edit the field Move out date.
But you will see the same number tomorrow, next week etc. - cause date.now() is not dynamical. You need a workaround which I've described multiple times in this forum.
`var start = moment(@Move Out Date);var in = moment(@Move In Date);var today = moment(@max of today's date); // = the date field from the related extra appvar end = in != null ? in : today;end.diff(start,"d") // difference in days;`
`end.diff(start,"d") + 1 `