title: how insert a datetime in mongoose js
body: <p>How can I insert a datetime in mongoose js?, I know a datetime is a Date in Schema.</p>
  
  <p>This is my schema:</p>
  
  <pre><code> const mongoose = require('mongoose');
   const { Schema } = mongoose;
  
   const todoSchema = new Schema({
      name: String,
      description: String,
      isDone: Boolean,
      createdAt: Date,
      updatedAt: Date
     });
    mongoose.model('todos', todoSchema);
  </code></pre>
  
  <p>This is my post route:</p>
  
  <pre><code> app.post('/api/todos', async (req, res) =&gt; {
  
        const { name, description, isDone,createdAt,updatedAt} = req.body;
  
          const todo = new Todo({
                      name,
                      description,
                      isDone,
                      createdAt,
                      updatedAt
                                });
  
                  try {
                      let newTodo = await todo.save();
                       res.status(201).send(newTodo);
                       } catch (err) {
                          if (err.name === 'MongoError') {
                                res.status(409).send(err.message);
                               }
                               res.status(500).send(err);
                               }
                       });
  </code></pre>
  
  <p>This is my date time picker input:</p>
  
  <pre><code>  import React from 'react';
    import DateTimePicker from 'react-widgets/lib/DateTimePicker';
    import Moment from 'moment';
    import momentLocalizer from 'react-widgets-moment';
  
   Moment.locale('en');
  
   momentLocalizer();
  
   const DateTimePickerInput = ({
       label,
       input,
       format,
       width,
       placeholder,
       defaultValue,
       meta: { touched, error },
     }) =&gt; {
          return (
                  &lt;div className='form-group'&gt;
                  &lt;label forname={input.name}&gt;{label}&lt;/label&gt; &lt;br /&gt;
                    &lt;DateTimePicker
                       placeholderText={placeholder}
                       className='form-control'
                        /&gt;
                  &lt;div className='text-danger' style={{ marginBottom: '20px' }}&gt;
                  {touched &amp;&amp; error}
                   &lt;/div&gt;
                    &lt;/div&gt;
                        );
                         };
             export default DateTimePickerInput;
  </code></pre>
  
  <p>And this my todo form with date time picker field:</p>
  
  <pre><code>       &lt;Field
              name='createdAt'
              component={DateTimePickerInput}
              dateFormat='dd-MM-yyyy'
              // dateFormat='dd-MM-yyyy H:mm'
              // showTimeSelect
              // timeFormat='HH:mm'
              placeholder='todoCreatedAt...'
              label='CreatedAt'
               /&gt;
            &lt;Field
                 name='updatedAt'
                 component={DateTimePickerInput}
                 dateFormat='dd-MM-yyyy'
                 // dateFormat='dd-MM-yyyy H:mm'
                 // showTimeSelect
                 //timeFormat='HH:mm'
                 placeholder='todoUpdatedAt...'
                 label='UpdatedAt'
                   /&gt;
  </code></pre>
  
  <p>How can I insert a datetime, in this case, createdAt and updatedAt in data base. Maybe I'm doing wrong post route. 
  I expect createdAt and updatedAt saved in database but real output those data are not saved in database.</p>
  
  <p>What is wrong?</p>