# Input type date ng-model

**URL:** <https://discourse.nodered.org/t/input-type-date-ng-model/5941>\
**Category:** General\
**Created:** [18 December 2018 15:01 UTC](https://discourse.nodered.org/t/input-type-date-ng-model/5941 "2018-12-18T15:01:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hathemi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hathemi/32/3792_2.png) [@hathemi](https://discourse.nodered.org/u/hathemi)\
**Post date:** [18 December 2018 15:01 UTC](https://discourse.nodered.org/t/input-type-date-ng-model/5941/1 "2018-12-18T15:01:54Z")

</div>

i have affect curent day to the input date to be the default valut.  
how can i affect this value to ng-model??  
also  
how an i use input type date with ng-model without getting this error in send. **```**  
**Error: [ngModel:datefmt]**

```auto

```

---

<div class="post-metadata">

**Author:** ![hugobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hugobox/32/2948_2.png) [@hugobox](https://discourse.nodered.org/u/hugobox)\
**Post date:** [18 December 2018 23:17 UTC](https://discourse.nodered.org/t/input-type-date-ng-model/5941/2 "2018-12-18T23:17:01Z")

</div>

Please share what you have so far.

---

<div class="post-metadata">

**Author:** ![hathemi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hathemi/32/3792_2.png) [@hathemi](https://discourse.nodered.org/u/hathemi)\
**Post date:** [19 December 2018 00:49 UTC](https://discourse.nodered.org/t/input-type-date-ng-model/5941/3 "2018-12-19T00:49:16Z")

</div>

what i'am trying to do is set default value of input date to current day and bind this value to ng-model.

> ```
> <input type="date" ng-model="msg.payload.dateselected" id="date" name="Date" ><br>
> {{msg.payload.dateselected}}
> 
> ```

```
 <input type="text" ng-model="msg.machine" id="machine" name="Machine" placeholder="Machine" ng-virtual-keyboard/><br>
  <button id="myBtn" ng-click="output(msg)" ng-disabled="(msg.machine == null)" >save</button>

<script>
 (function($scope) {
 var date = new Date();
  var local = new Date(date);
  local.setMinutes(date.getMinutes() - date.getTimezoneOffset());
  document.getElementById("date").value = local.toJSON().slice(0, 10);
      $scope.msg.payload.dateselected = $('#date').val();
})(scope);

(function($scope) {
     $scope.msg = {"machine":""}

     $scope.output = function(msg){

         $scope.msg.machine = $('#machine').val()

           $scope.send(msg)
            $scope.msg.payload = ""
         
      }
  })(scope);
</script>

```

---

<div class="post-metadata">

**Author:** ![hugobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hugobox/32/2948_2.png) [@hugobox](https://discourse.nodered.org/u/hugobox)\
**Post date:** [19 December 2018 03:02 UTC](https://discourse.nodered.org/t/input-type-date-ng-model/5941/4 "2018-12-19T03:02:44Z")

</div>

It was harder than I thought, but here's what I came up with:

```auto
<input type="date" ng-init="date = StrToDate(msg.payload)" ng-model="date" ng-change="msg.payload = date.toLocaleDateString(); send(msg)">

<script>
 (function($scope) {
    $scope.msg = {}
    $scope.msg.payload = new Date()
    $scope.StrToDate = function (str) {
        return new Date(str);
    }
})(scope);
</script>
```
