Findfirst with dates

The following script throws an error, and I wonder what the correct syntax is for achieving what I want:

id_date = findfirst(market_days_all, market_day)

ERROR: MethodError: no method matching findfirst(::Vector{Date}, ::Date)

The following works:

using Dates
market_day = Date(2022, 1, 1)
market_days_all = collect(Date(2021,12,1):Day(1):Date(2022,2,1))
id_date = findfirst(==(market_day), market_days_all)

I had to create some mock data to test this on, but the gist is that the findfirst function takes a function that tests for true or false (i.e. is it equal to market_day?), and a collection of things to test said function on.

You’ll find a lot more help if you just type ? followed by the function you’re trying to use (i.e. findfirst) in the REPL.

1 Like