0

i'm trying to show notifications to users only for today's entered matches some date in this format 2017/11/13 15:02 from record

NOTE:2017/11/13 15:02 will always change, used for the sake of comparison

in pseudo code

 if(today's date passed and dont match 2017/11/13 15:02){
    //don't send notification
 }else{
   //send notification
}

i have tried something like this

var comparisionDate = '2017/11/13 15:02';

var todaysDate = new Date();  // current date

// further i don't know to compare

if(comparisionDate == todaysDate ){
   //send notifications
}else{
  // don't show notification
}

1 Answers1

0

The getTime() method will give you the time stamp in milliseconds since the epoch, you can use it with the new Date, Date.parse() however already returns a time stamp.

var comparisionDate = Date.parse('2017/11/13 15:02');

var todaysDate = new Date();  // current date

// further i don't know to compare

if(comparisionDate == todaysDate.getTime() ){
   //send notifications
   
   alert("Today's date " + todaysDate.getTime() + " equals " + comparisionDate);
}else{
  // don't show notification
  alert("Today's date " + todaysDate.getTime() + " Not equals " + comparisionDate);
}
Efi Shtainer
  • 394
  • 3
  • 8
  • for this **date** also `var comparisionDate = Date.parse('2017/11/10 15:02'); ` it is showing `not equal ` **must be equal?** –  Nov 10 '17 at 11:07
  • It computes time in milliseconds , so if one second difference doesn't really matters, divide both time stamps by 1000 and then compare, for minutes by 60000, etc – Efi Shtainer Nov 10 '17 at 15:22