title: How can I use DateOnly/TimeOnly query parameters in ASP.NET Core 6?
body: <p>As of .NET 6 in ASP.NET API, if you want to get <code>DateOnly</code> (or <code>TimeOnly</code>) as query parameter, you need to separately specify all it's fields instead of just providing a string (&quot;2021-09-14&quot;, or &quot;10:54:53&quot; for <code>TimeOnly</code>) like you can for <code>DateTime</code>.</p>
  <p>I was able to fix that if they are part of the body by adding adding custom JSON converter (<code>AddJsonOptions(o =&gt; o.JsonSerializerOptions.Converters.Add(...))</code>), but it doesn't work for query parameters.</p>
  <p>I know that could be fixed with model binder, but I don't want to create a model binder for every model that contains <code>DateOnly/TimeOnly</code>. Is there a way to fix this application wide?</p>
  <p><strong>Demo:</strong></p>
  <p>Lets assume you have a folowwing action:</p>
  <p><code>[HttpGet] public void Foo([FromQuery] DateOnly date, [FromQuery] TimeOnly time, [FromQuery] DateTime dateTime)</code></p>
  <p>Here's how it would be represented in Swagger:</p>
  <p><a href="https://i.stack.imgur.com/lOgBy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lOgBy.png" alt="enter image description here" /></a></p>
  <p>I want it represented as three string fields: one for <code>DateOnly</code>, one for <code>TimeOnly</code> and one for <code>DateTime</code> (this one is already present).</p>
  <p>PS: It's not a Swagger problem, it's ASP.NET one. If I try to pass <code>?date=2021-09-14</code> manually, ASP.NET wouldn't understand it.</p>