title: How to check if user subscription has expired by comparing if maturity date has passed
body: <p>I am currently working on a web app where subscriptions have maturity date, I currently have a middleware that checks if current date equals to the maturity date.</p>
  <pre><code>  const userdate = user.subscription.maturityDate
              .toString()
              .slice(0, 15);
  
            const day = new Date().toString().slice(0, 15);
  
            if (userdate === day) {
              user.isDue = true;
              user.save();
              req.flash(
                &quot;succes&quot;,
                &quot;Your current plan has expired please make a withdrawal&quot;
              );
              res.send(&quot;Your current plan has expired please make a withdrawal&quot;);
  </code></pre>
  <p>The problem with the logic is that it only works when todays date is equal to the maturity date, but I want to check if the maturity date has passed. I have tried using a function that checks if the date is in the past but its not working.</p>
  <pre><code>var dateInPast = function (firstDate, secondDate) {
                        if (
                          firstDate.setHours(0, 0, 0, 0) &lt;=
                          secondDate.setHours(0, 0, 0, 0)
                        ) {
                          return true;
                        }
  
                        return false;
                      };
                      dateInPast(userdate, day);
  </code></pre>
  <p>Can someone please point out what am doing wrong.</p>