Calculate days passed since event
I would simply like to display how many days have passed since an experiment was performed (a date field in the Experiments app). Any suggestion as to how this calculation would look? I suppose it involves pulling the current date, but I have no clue as to how to achieve this...
-
Philip, as a part of a logging app for a study, there is a date field simply called "Date of experiment". Following this, I've entered the formula according to my first reply: moment(Date of experiment).fromNow();
(Addition: if you add "true" in the last parentheses -- moment(Date of experiment).fromNow(true); -- the output changes from for instance "7 days ago" to just "7 days")
All this is just to keep track of how much time has elapsed since the experiment! -
John, apparently by writing
var now = moment(Date of experiment)
var then = moment(Date of termination)
then.diff(now, 'days')I know I've seen a way to also customize entirely the output, so that you could for example get something similar to:
"years: 0
months:1
days:3
hours:...."
and so on. -
Most of the date requirements I have don't have termination dates yet. I was seeking to check them again today's date, i.e., how many days since this was sent out. It looks like the javascript you included requires a termination date, so it won't work for me. I can't figure out how to have today's date replace the termination date in your script because it's never defined correctly no mater what I put in. Anyone have any ideas?
This is my script as it exists from this thread....
moment(Start date).fromNow();
-
Maybe the documentation over at http://momentjs.com/ is helpful? Also, just to be clear, are you referring to the date field (by placing @ in front of the name)?
Please sign in to leave a comment.
Comments
7 comments