# Arguments, unexpected behavior

**URL:** <https://discourse.julialang.org/t/arguments-unexpected-behavior/18263>\
**Category:** General Usage\
**Tags:** dates\
**Created:** [December 3, 2018, 11:46pm UTC](https://discourse.julialang.org/t/arguments-unexpected-behavior/18263 "2018-12-03T23:46:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrykironde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrykironde/32/6307_2.png) [@henrykironde](https://discourse.julialang.org/u/henrykironde)\
**Post date:** [December 3, 2018, 11:46pm UTC](https://discourse.julialang.org/t/arguments-unexpected-behavior/18263/1 "2018-12-03T23:46:58Z")

</div>

[https://github.com/JuliaLang/julia/issues/30252](https://github.com/JuliaLang/julia/issues/30252)  
[https://docs.julialang.org/en/v1/manual/functions/#Optional-Arguments-1](https://docs.julialang.org/en/v1/manual/functions/#Optional-Arguments-1)

```bash
Julia
               _
   _ _ _(_)_ | A fresh approach to technical computing
  (_) | (_) (_) | Documentation: https://docs.julialang.org
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 0.7.0 (2018-08-08 06:46 UTC)
 _/ |\ __'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-w64-mingw32

```

```bash
julia> function Date(y::Int64, m::Int64=1, d::Int64=1)
           err = validargs(Date, y, m, d)
               err === nothing || throw(err)
                   return Date(UTD(totaldays(y, m, d)))
                   end
Date (generic function with 3 methods)

```

```bash

julia> Date(2000, 12, 12)
ERROR: UndefVarError: validargs not defined
Stacktrace:
 [1] Date(::Int64, ::Int64, ::Int64) at .\REPL[1]:2
 [2] top-level scope at none:0

```

```bash
julia> function Re_Date(y::Int64, m::Int64=1, d::Int64=1)
           err = validargs(Re_Date, y, m, d)
               err === nothing || throw(err)
                   return Re_Date(UTD(totaldays(y, m, d)))
                   end
Re_Date (generic function with 3 methods)

```

```bash
julia> Re_Date(2000, 12, 12)
ERROR: UndefVarError: validargs not defined
Stacktrace:
 [1] Re_Date(::Int64, ::Int64, ::Int64) at .\REPL[3]:2
 [2] top-level scope at none:0

```

```bash
julia> Re_Date(2000, 12)
ERROR: UndefVarError: validargs not defined
Stacktrace:
 [1] Re_Date(::Int64, ::Int64, ::Int64) at .\REPL[3]:2 (repeats 2 times)
 [2] top-level scope at none:0

julia>

```

```bash
julia> versioninfo()
Julia Version 0.7.0
Commit a4cb80f3ed (2018-08-08 06:46 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 4, 2018, 12:19am UTC](https://discourse.julialang.org/t/arguments-unexpected-behavior/18263/2 "2018-12-04T00:19:41Z")

</div>

It looks like that section of the manual is a bit out-of-date. You’ll need:

```julia
using Dates

```

and you’ll need to replace `validargs` with `Dates.validargs`.

---

<div class="post-metadata">

**Author:** ![aaowens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaowens/32/12101_2.png) [@aaowens](https://discourse.julialang.org/u/aaowens)\
**Post date:** [December 4, 2018, 12:21am UTC](https://discourse.julialang.org/t/arguments-unexpected-behavior/18263/3 "2018-12-04T00:21:53Z")

</div>

It looks like those functions, like `validargs`, are not exported from the Dates module. This works:

```julia
julia> function Date(y::Int64, m::Int64=1, d::Int64=1)
           err = Dates.validargs(Date, y, m, d)
           err === nothing || throw(err)
           return Date(Dates.UTD(Dates.totaldays(y, m, d)))
       end
Date

julia> Date(2000)
2000-01-01

```

I think you weren’t intended to actually run the `function Date` code. It’s just showing you how the method was defined in the `Dates` module. The code works fine if you don’t run it.

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [May 14, 2022, 8:07am UTC](https://discourse.julialang.org/t/arguments-unexpected-behavior/18263/4 "2022-05-14T08:07:27Z")

</div>

Here is the current status of: “Dates.validargs()”

```julia
using Dates
function Date(y::Int64, m::Int64=1, d::Int64=1)
    err = Dates.validargs(Date, y, m, d)
    err === nothing || throw(err)
    return Date(UTD(totaldays(y, m, d)))
end
Date(2000, 12, 12)

```

Throws:

```julia
ERROR: MethodError: no method matching validargs(::typeof(Date), ::Int64, ::Int64, ::Int64)
[...]

```

```julia
versioninfo()
Julia Version 1.7.2

```

Any ideas?

---

<div class="post-metadata">

**Author:** ![chandras002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chandras002/32/707_2.png) [@chandras002](https://discourse.julialang.org/u/chandras002)\
**Post date:** [May 6, 2023, 12:40pm UTC](https://discourse.julialang.org/t/arguments-unexpected-behavior/18263/5 "2023-05-06T12:40:04Z")

</div>

Getting same error in version 1.8.5. Any thoughts?  
`MethodError: no method matching validargs(::typeof(Date), ::Int64, ::Int64, ::Int64) Closest candidates are:`
