# Date coercion in arrays

**URL:** <https://discourse.dry-rb.org/t/date-coercion-in-arrays/1206>\
**Category:** dry-validation\
**Created:** [March 1, 2021, 4:58pm UTC](https://discourse.dry-rb.org/t/date-coercion-in-arrays/1206 "2021-03-01T16:58:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpawlyn](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/jpawlyn/32/609_2.png) [@jpawlyn](https://discourse.dry-rb.org/u/jpawlyn)\
**Post date:** [March 1, 2021, 4:58pm UTC](https://discourse.dry-rb.org/t/date-coercion-in-arrays/1206/1 "2021-03-01T16:58:52Z")

</div>

Hello. I’ve searched through the documentation but I haven’t found a way to coerce valid string dates when they are in an array for dry-validation 1.6.0.

When outside an array, the date coercion works as expected ie:

```ruby
class TestDateCoercion1 < Dry::Validation::Contract
  params do
    optional(:start_date).value(:date)
  end
end

contract = TestDateCoercion1.new
contract.call(start_date: '2021-03-01')

```

But inside an array, we see an error ie:

```ruby
class TestDateCoercion2 < Dry::Validation::Contract
  params do
    required(:projects).each do
      schema do
        optional(:start_date).value(:date)
      end
    end
  end
end

contract = TestDateCoercion2.new
contract.call(projects: [start_date: '2021-03-01'])

```

Any suggestions much appreciated. Thanks,

Jolyon

---

<div class="post-metadata">

**Author:** ![jpawlyn](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/jpawlyn/32/609_2.png) [@jpawlyn](https://discourse.dry-rb.org/u/jpawlyn)\
**Post date:** [March 2, 2021, 6:06am UTC](https://discourse.dry-rb.org/t/date-coercion-in-arrays/1206/2 "2021-03-02T06:06:00Z")

</div>

Turns out the solution was to use `array(:hash) instead of `each`. ie

```ruby
class TestDateCoercion2 < Dry::Validation::Contract
  params do
    required(:projects).array(:hash) do
      optional(:start_date).value(:date)
    end
  end
end

contract = TestDateCoercion2.new
contract.call(projects: [start_date: '2021-03-01'])

```
