develop05
develop05

Reputation: 485

return moment.js function in days number only without strings

So, I'm using moment.js to calculate number of days between the current date and a given date and it returns something like "a month ago" or "5 days ago". I want it to just return "30" or "5" instead.

import moment from "moment";


console.log(moment("2018-09-01", "YYYY-MM-DD").fromNow())

Upvotes: 0

Views: 102

Answers (1)

seunggabi
seunggabi

Reputation: 1822

You can do this.

console.log(moment().diff(moment("2018-09-01"), "days"))

Upvotes: 3

Related Questions