# Understanding splice!

**URL:** <https://discourse.julialang.org/t/understanding-splice/69497>\
**Category:** New to Julia\
**Tags:** question, vector\
**Created:** [October 10, 2021, 2:03am UTC](https://discourse.julialang.org/t/understanding-splice/69497 "2021-10-10T02:03:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sransome](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sransome/32/29810_2.png) [@sransome](https://discourse.julialang.org/u/sransome)\
**Post date:** [October 10, 2021, 2:03am UTC](https://discourse.julialang.org/t/understanding-splice/69497/1 "2021-10-10T02:03:15Z")

</div>

Hi,  
I’m having trouble with splice!  
This works fine  
d=[1,3]  
splice!(d,2:1,2)  
julia\> d  
3-element Vector{Int64}:  
1  
2  
3

But this does not work…  
d=[Date(“2021-01-01”),Date(“2021-03-01”)]  
splice!(d,2:1,Date(“2021-02-01”))  
fails with ERROR: MethodError: no method matching length(::Date)

splice!(d,2:1,) also doesn’t work  
I can’t find any documentation referring to limitations of splice, can anyone point me in the right direction? Or perhaps give me an alternate approach for inserting Date elements into an array of Dates.

Windows 10  
VScode 1.6.1  
Julia Ext 1.4.3  
Julia 1.6.3  
Thanks  
Steve

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [October 10, 2021, 2:10am UTC](https://discourse.julialang.org/t/understanding-splice/69497/2 "2021-10-10T02:10:38Z")

</div>

Try wrapping the spliced value in a vector, or use `insert!`:

```julia
julia> splice!(d, 2:1, [Date("2021-02-01")])
Date[]

julia> d
3-element Vector{Date}:
 2021-01-01
 2021-02-01
 2021-03-01

```

```julia
julia> insert!(d, 2, Date("2021-02-01"))
3-element Vector{Date}:
 2021-01-01
 2021-02-01
 2021-03-01

```

---

<div class="post-metadata">

**Author:** ![sransome](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sransome/32/29810_2.png) [@sransome](https://discourse.julialang.org/u/sransome)\
**Post date:** [October 10, 2021, 2:23am UTC](https://discourse.julialang.org/t/understanding-splice/69497/3 "2021-10-10T02:23:27Z")

</div>

Thanks stillyslalom, those worked perfectly. Julia continues to humble me but I love it.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 10, 2021, 12:31pm UTC](https://discourse.julialang.org/t/understanding-splice/69497/4 "2021-10-10T12:31:44Z")

</div>

FWIW, wrapping the Date in a tuple works too:

```julia
using Dates
d=[Date("2021-01-01"), Date("2021-03-01")]
splice!(d, 2:1, (Date("2021-02-01"),))

```

From the help doc:  
_If specified, replacement values from an ordered collection will be spliced in place of the removed items; in this case, indices must be a UnitRange._
