0

I want to check if the event date is today. If yes then show some text. If target event date does not pass then show some text and also check if the event date already passed. here is my code

var evnt_date = "2018-09-18";
wishTime(evnt_date);

function wishTime(evnt_dt){
 var today = new Date();
 var evnt = new Date(evnt_dt);
 
 if(Date.parse(evnt) == Date.parse(today)){
  $("#header-slogan").html($("#header-slogan").html());
 }else if(Date.parse(evnt) > Date.parse(today)){
  $("#header-slogan").html($("#header-slogan").html() + " In Advance");
 }else if(Date.parse(evnt) < Date.parse(today)){
  $("#header-slogan").html("Belated " + $("#header-slogan").html());
 }
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="header-slogan">Wish you...</div>

In this code you can check if event date is today, then it will show belated. After debug by displaying the two dates i.e today, evnt, I saw it compares time part also. So is there any way to compare date only? I dont want to use seperate plugin for that.

Ashis Biswas
  • 747
  • 11
  • 28
  • calculate date difference – Empty Brain Sep 18 '18 at 05:16
  • Possible duplicate of [How to check if input date is equal to today's date?](https://stackoverflow.com/q/8215556/608639), [Jquery function to compare date with current date](https://stackoverflow.com/q/14439471/608639), [check date with current date in jquery](https://stackoverflow.com/q/23629598/608639), etc. – jww Sep 18 '18 at 05:26
  • Thanks for the links @jww, the last one is the only one I saw comparing dates in the same timezone. Anything that uses `new Date('yyyy-mm-dd')` format is going to compare today in local time to the parsed date in UTC – Phil Sep 18 '18 at 05:31

0 Answers0