Unable to use DiffInDays function between birthday and now() dynamics 365

Viewed 914

I have a custom field of type decimal in the contact entity. This is a calculated field representing the difference in days between the birthday field and the current date. This is the expression I am using to make the calculation DiffInDays(birthdate, Now()). When I try to set this expression I get this error: You can't use Now(), which is of type dateTime, with the current function. This is because birthdate field has Date Only behavior and Now() function represents a date and time fraction. Is there any way that I can get only the date portion of the Now() datetime?

1 Answers

considering your are using Javascript, Convert birthdate to date object as new Date(birthdate) and now() with new Date() as below

dt1 = new Date(birthdate);
dt2 = new Date();
var diffindays = Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()) ) /(1000 * 60 * 60 * 24));
Related