title: Moment Display Birthdate Relative to Current Days DAYOFYEAR
body: <p>I am using <code>moment()</code> in my Angular app and I need to display the Birthdays (irrespective of the year) relative to the current days of the week. My server will send a list of birthdates coming up for this week in <code>YYYY-MM-DD</code> format and I want this to be shown like this (considering today's date is 2 March 2017):</p>
  
  <pre><code>BirthDate  - Display it to this year's day of the week
  2014-03-01 - Yesterday
  2016-03-02 - Today
  2015-03-03 - Tomorrow
  2014-03-04 - Saturday
  etc...
  </code></pre>
  
  <p>In my Angular 1.5 view, I can send the data to a <code>dayCheck</code> function like this:</p>
  
  <pre><code>&lt;p ng-repeat="person in birthdays"&gt;
    Name: {{person.name}} &lt;br&gt;
    When: {{vm.dayCheck(person.date)}}
  &lt;/p&gt;
  
  function dayCheck(date) {
     return moment(date).format('DD'); // ?? How can I return the days relative to user's day from this year??
  }
  </code></pre>
  
  <p><strong>My Answer:</strong></p>
  
  <p>This is what I have come up with since I posted the question. It doesn't look elegant and I am sure there is a better what to do this. But the working code I have to resolve this is:</p>
  
  <pre class="lang-js prettyprint-override"><code>function dayCheck(date) {
      var returnData = '';
      var birthDayDate = moment(date).format('DD');
      if (birthDayDate == moment().format('DD')) {
          var returnData = 'Today';
      }
      else if (birthDayDate == moment().subtract(1, 'days').format('DD')) {
          var returnData = 'Yesterday';
      }
      else if (birthDayDate == moment().add(1, 'days').format('DD')) {
          var returnData = 'Tomorrow';
      }
      else {
          var momentDate = moment(date);
          var month = momentDate.format('MM');
          var date  = momentDate.format('DD');
          var currentMonth = moment().format('MM');
          if (currentMonth == 12 &amp;&amp; month == 1) {
              var year = moment().add(1, "years").year();
          }
          else if (currentMonth == 1 &amp;&amp; month == 12) {
              var year = moment().subtract(1, "years").year();
          }
          else {
              var year = moment().year();
          }
          var dateFormat = year + '-' + month + '-' + date;
          var returnData = moment(dateFormat).format('dddd');
      }
      return returnData;
  }
  </code></pre>
  
  <p>Please do let me know if there is a better, elegant way to do the above. I also suspect the above will fail if the Birthday was on the 29th Feb of a leap year.</p>