# How to update a date field using JS

**URL:** https://forums.knack.com/t/how-to-update-a-date-field-using-js/10953
**Category:** API & Custom Code
**Created:** [August 25, 2021, 3:10pm UTC](https://forums.knack.com/t/how-to-update-a-date-field-using-js/10953 "2021-08-25T15:10:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![DeeGee](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@DeeGee](https://forums.knack.com/u/DeeGee)
#### Post date: [August 25, 2021, 3:10pm UTC](https://forums.knack.com/t/how-to-update-a-date-field-using-js/10953/1 "2021-08-25T15:10:12Z")

</div>

I’m trying to create a record that contains a date field, and failing badly! Nothing is getting written for the date at all.

The code is catching the submit action on one record, and creating a new record in another table that uses the date field from the submitted record.

Here’s the (minimal) code:

```auto
$(document).on('knack-form-submit.view_19', function(event, view, record) {
	var user = Knack.getUserAttributes().id;
    if (user) {
      console.log("Close Date: %s", record.field_78);
      console.log("Close Date raw: %o", record.field_78_raw);
      $.ajax({
          url: 'https://api.knack.com/v1/pages/scene_50/views/view_66/records',
          type: 'POST',
          async: false,
          headers: {'X-Knack-Application-Id': 'XXXXXXXXXXXXXXXXX', 'X-Knack-REST-API-Key': 'knack', 'Authorization': Knack.getUserToken(), 'Content-Type': 'application/json'},
          data: JSON.stringify({'field_95': record.field_78_raw.date}),
          success: function (response) {
            console.log("Record created");
          },
          error: function(response){
            console.log(response);
          }
       });
    }
});

```

field\_95 is a date field in the destination record, field 78 in the source record, both formatted as mm/dd/yyyy.

I’ve tried all of the following, all with no luck:

```auto
data: JSON.stringify({'field_95': record.field_78})
data: JSON.stringify({'field_95': record.field_78_raw})
data: JSON.stringify({'field_95': record.field_78_raw.date})
data: JSON.stringify({'field_95': {'date': record.field_78_raw.date})

```

The console shows what I would expect:

> Close Date: 11/30/2021  
> VM16773:12 Close Date raw: {date: “11/30/2021”, date\_formatted: “11/30/2021”, hours: “12”, minutes: “00”, am\_pm: “AM”, …}

Any suggestions?

---

<div class="post-metadata">

### Author: ![DeeGee](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@DeeGee](https://forums.knack.com/u/DeeGee)
#### Post date: [August 25, 2021, 3:39pm UTC](https://forums.knack.com/t/how-to-update-a-date-field-using-js/10953/2 "2021-08-25T15:39:43Z")

</div>

OK, turns out it was a really dumb error on my part elsewhere!

For reference, the correct syntax is the very simple  
`data: JSON.stringify({'field_95': record.field_78})`
