# setFieldValue for date field

**URL:** <https://forum.wixstudio.com/t/setfieldvalue-for-date-field/23835>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 29, 2020, 3:18pm UTC](https://forum.wixstudio.com/t/setfieldvalue-for-date-field/23835 "2020-04-29T15:18:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kroberts](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kroberts](https://forum.wixstudio.com/u/kroberts)\
**Post date:** [April 29, 2020, 3:18pm UTC](https://forum.wixstudio.com/t/setfieldvalue-for-date-field/23835/1 "2020-04-29T15:18:55Z")

</div>

I’m calling setFieldValue to set a field that is a date in the underlying collection. No matter what format I use, the entry is set but with an error " The value does not match the field type Date and Time."

I’ve tried strings, numbers … all flavors of Date() values to no avail.

Is there a working example of setFieldValue for a Date and Time field?

Thanks

---

<div class="post-metadata">

**Author:** ![anastasiias](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anastasiias/32/15771_2.png) [@anastasiias](https://forum.wixstudio.com/u/anastasiias)\
**Post date:** [May 11, 2020, 11:58am UTC](https://forum.wixstudio.com/t/setfieldvalue-for-date-field/23835/2 "2020-05-11T11:58:56Z")

</div>

Hello,

You can do it using a variable, something like this:

```javascript
var dateExample = new Date("2019-01-02");

$w.onReady(() => {
  $w("#dataset1").onReady(() => {
    $w("#dataset1").setFieldValue("timeField", dateExample);

  });

});

```

Where:  
#dataset1 - ID of the dataset in question, that you can find in the Properties Panel ([Velo: Working with the Properties & Events Panel | Help Center | Wix.com](https://support.wix.com/en/article/corvid-working-with-the-properties-panel))  
timeField - Field key of the relevant field.
