How do I check a date is actually today (the same date) rather than the difference between hours in a day?
I have three timestamps as examples, one is today (22/07/14) and the other two are yesterday (21/07/14)
1406019110000 // today
1405951867000 // yesterday
1405951851000 // yesterday
I have tried this but all return false:
timestamp = moment.tz(timestamp, tz.name());
var today = moment('DD/MM/YYYY').isAfter(timestamp, 'DD/MM/YYYY');
console.log(today);
You can try this
You can use
isSame()
, limiting the granularity to a day:You can use the
startOf
andisSame
methods together to achieve your goal here.Running
startOf('day')
on a moment object will set that moment to - you guessed it - the start of the day it occurs on. If you convert each of your timestamps using this method you can easily compare them to one another usingisSame()
.For example:
You can try this,
Here is the demo