Published
Edited
Jul 7, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
/* dateDiffToHuman = (date) => {
const weeksDiff = moment().diff(date, 'weeks')
if(weeksDiff <= 4) {
return `${weeksDiff} weeks ago`
}
return moment(date).format('Y-MM-DD')
}
*/dateDiffToHuman = (date) =>
moment(date).toDate().toLocaleDateString(undefined, {
month: 'short',
day: 'numeric',
...(!moment(date).isSame(new moment(), 'year') && { year: 'numeric'})
})
Insert cell
Insert cell
dateDiffToHuman(moment('2021-02-01'))
Insert cell
dateDiffToHuman(moment('2020-02-01'))
Insert cell
Insert cell
moment = require('moment')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more