title: Uncaught TypeError: getFullYear is not a function
body: <p>I keep getting the error "Uncaught TypeError: date3.getFullYear is not a function"</p>
  
  <p>I have a date variable in both SQL and JS format (passed from another function as arguments):</p>
  
  <pre><code>min1 - in SQL format. [Like - '2017-08-13 0:0:00']
  mindate - in JS format. [Like - 'Sun Aug 13 2017 00:00:00 GMT+0530 (India Standard Time)' ]
  </code></pre>
  
  <p>I am using these variables to create a new date variable called 'date3'. I have tried the following:</p>
  
  <pre><code>var date2 = min1.split(' ')[0]; // should give me '2017-08-13'
  date3 = new Date(date2);
  </code></pre>
  
  <p>AND, </p>
  
  <pre><code>var date3 = new Date();
  date3 = mindate;
  </code></pre>
  
  <p>AND,</p>
  
  <pre><code>var date3 = mindate;
  </code></pre>
  
  <p>AND,</p>
  
  <pre><code>var Y = parseInt(min1.split(' ')[0].split('-')[0]);       // 2017
  var M = parseInt(min1.split(' ')[0].split('-')[1]) - 1;   // 7
  var D = parseInt(min1.split(' ')[0].split('-')[2]);       // 13
  var date3 = new Date(Y,M,D);
  </code></pre>
  
  <p>And when I console.log the date3, it gives the correct date. But when I do a getFullYear() on date3, it gives the error: "Uncaught TypeError: getFullYear is not a function"</p>
  
  <p>I have tried everything and nothing seems to work. (I even read some other similar questions, and some answers were saying its because 'date' is a 'moment' object, but I don't understand what it means and how it can help resolve this).</p>
  
  <p>UPDATE:</p>
  
  <p>Here's how I am using the getFullYear function. I have tried two things:</p>
  
  <pre><code>datestring = date3.getFullYear() + '-' + (date3.getMonth()+1) + '-' + (date3.getDate());
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>var y = date3.getFullYear(),
  m = date3.getMonth() + 1, // january is month 0 in javascript
  d = date3.getDate();
  </code></pre>
  
  <p>Am using this inside a 'for' loop, and the date3 was created just above the loop as follows:</p>
  
  <pre><code>var date3 = new Date(Y,M,D);
  console.log(date3);
  
  for (k=1; k&lt;=x; k++) {
  
      var y = date3.getFullYear(),
      m = date3.getMonth() + 1, // january is month 0 in javascript
      d = date3.getDate();
      var pad = function(val) { var str = val.toString(); return (str.length &lt; 2) ? "0" + str : str};
      datestring = [y, pad(m), pad(d)].join("-");
      console.log("DATESTRING", datestring);
  
      divCode += '&lt;div class="swiper-slide" id="_' + datestring + '" data-hash="' + datestring + '"&gt;&lt;b&gt;' +datestring+ '&lt;/b&gt;&lt;br&gt;&lt;br&gt;' +tableCode+ '&lt;/div&gt;';
  
      // Incrementing date by 1
      date3 = date3.setDate(date3.getDate() + 1);
  
  
  }
  </code></pre>