title: How to format ng-model string to date for angular material datepicker
body: <p>I have a <strong>mongoose</strong> connection to a database containing Date objects in a collection. I want to view these Date objects using Angular Material's <code>DatePicker</code> control. The Date object follow the <strong>ISO string format</strong>.</p>
  
  <p>Here is a code snippet:</p>
  
  <pre><code>&lt;md-datepicker 
       ng-model="license.expirationdate" md-placeholder="Enter date"&gt;
  &lt;/md-datepicker&gt;    
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p>The <code>ng-model</code> for <code>md-datepicker</code> must be a Date instance.</p>
  
  <p>When researching, I found that you can use filters to create a Date instance but this did not work for me -> I got an error message saying that the model value is non-assignable when using a simple filters. The filter simply returned a new Date object based on the string input.</p>
  
  <p>How can I format the strings to Date objects while still allowing for <code>ng-model</code> changes?</p>
  
  <p>EDIT: schema for mongoose
  var Schema = mongoose.Schema;</p>
  
  <pre><code>var Schema = mongoose.Schema;
  
  var modelschema = new Schema({
      name : String,
      licensetype : String,
      activationcount : Number,
      expirationdate: Date,
      key : String
  })
  </code></pre>
  
  <p>here is the express routing which populates the schema</p>
  
  <pre><code>app.post('/licenses', function (req, res) {
  
      console.log(req.body.expirationDate);
      License.create({
  
          name: req.body.licenseName,
          licensetype: req.body.licenseType,
          activationcount: 0,
          expirationdate: req.body.expirationDate,
          key: "123456"
      }, function (err, license) {
  
          if (err) {
              res.send(err);
              console.log(err);
          }
  
          //Send user back to main page
          res.writeHead(301, {
              'Location': '/',
              'Content-Type': 'text/plain'
          });
          res.end();
      }
      )
  
  });
  </code></pre>