I have a fileClass for prescriptions that includes a property for the date filled (dateFilled) and the ‘Days Supplied’ (daysSupplied). I’d like to have another field for a date of when that prescription would run out (dateFinished), which could be calculated by adding the days supplied to the date filled. I tried using a ‘formula’ field type with the formula set to current.dateFilled + current.daysSupplied
but it returns a large number. When I convert that number to a date it returns dateFilled. Any ideas on how to accomplish my goal?
When you use a date field as a number it usually returns the number of (milli-)seconds since epoch (1970), so if you just add 7 (assuming its a week) and it’s just a few seconds you might understand why it fails…
So either you need to use some date functions to add the corresponding duration, or you need to multiply your unit how ever many (milli-)seconds there are in a day.
Yea, I tried a bunch of things along that line, including multiplying the daysSupplied x 86400 and adding that to the date as epoch, but wasn’t getting anywhere. I explored some different avenues, and finally figured it out. Here’s what ended up working to derive my ‘dateFinished’ automatically:
moment(new Date(current.dateFilled)).add(current.daysSupplied,'d').format('YYYY-MM-DD')
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.