I need to do a conditional where I test whether the date from a date picker has passed already. I need to compare it to todays date using Date.now(); which returns milliseconds.
when I my log date picker date from my object - listOfEventsObject[i].date - it prints in this form:
**2017-08-15** .
while date.now() outputs this: **1503904013430**
how can I convert the date picker date in order to see if the time has passed?
UPDATE It does not work to use getTime(); when I use getTime(); it removes everything from the array. I only need passed dates left out of the array.
my code:
function getPostsSuccess (listOfEventsObject){ /*callback which passes
array to loop*/
for (var i in listOfEventsObject) {
if(listOfEventsObject[i].date.getTime() < Date.now()){
this.listOfEvents.push(listOfEventsObject[i]);
}//close if
}//close loop
}//close callback
You can use the
.getTime()
method of the date object to get milliseconds that can be compared toDate.now()
.