I have a date & time format: 2019-11-25 09:49:19
. How can we compare this from current date & time and can display like: 3 days ago
or weeks/ hours/ min ago
After many hit and trails I found exact solution:
moment.utc("2019-12-04 12:00:24").local().startOf('seconds').fromNow()
Output:
30 minutes ago, 1 hour ago, 2 weeks ago
You can use moment.js
library. moment.js
moment("20111031", "YYYYMMDD").fromNow(); // 8 years ago
moment("20120620", "YYYYMMDD").fromNow(); // 7 years ago
moment().startOf('day').fromNow(); // 16 hours ago
moment().endOf('day').fromNow(); // in 8 hours
moment().startOf('hour').fromNow(); // an hour ago
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With