title: C# How to convert the date that have been retrieve from DB and Where should I write?
body: <p>In this task, I am trying to write a method that filters according to the date entered by the user. But I couldn't figure out where and how to write the format changing code.</p>
  <p>I have a DateTime object in database like this :<code>2022-08-09 11:42:26.3600000(y/m/d)</code></p>
  <p>When the user enters the date in the following format : <code>09/08/2022</code>, I am trying to show the data in the database in the following format : <code>09/08/2022 11:42</code> to the user. And when the user enters as <code>d/m/y</code>, the datas that matches this date will be returned as a list.</p>
  <p>If it matches more than one data, it will return as a list.</p>
  <p>this is my controller method:</p>
  <pre><code>[HttpGet(&quot;date/{date}&quot;)]
  [Produces(&quot;application/json&quot;)]
  [ProducesResponseType(StatusCodes.Status200OK)]
  [ProducesResponseType(StatusCodes.Status400BadRequest)]
  public async Task&lt;ActionResult&lt;Result&gt;&gt; GetPartySearchHistoriesByDate([BindRequired] DateTime date)
  {
    try
    {
      var items = await _mediator.Send(new GetPartySearchHistoriesByDateQuery() {Date = date});
  
      return Result.Ok(new
      {
        MatchCount = items.Count,
        Matches = items
      });
    }
    catch (Exception ex)
    {
              throw new SanctionException(&quot;An error occurred while fetching record.&quot;, ex);
    }
  }
  </code></pre>
  <p>This is Handler :</p>
  <pre><code>public async Task&lt;IList&lt;PartySearchHistoryVM&gt;&gt; Handle(GetPartySearchHistoriesByDateQuery request, CancellationToken cancellationToken)
  {
      var dates = await _partySearchHistoryRepository.GetListByDateAsync(request.Date);
      return dates.Adapt&lt;IList&lt;PartySearchHistoryVM&gt;&gt;();
  }
  </code></pre>
  <p>this is dapper method:</p>
  <pre><code>public async Task&lt;List&lt;PartySearchHistoryDto&gt;&gt; GetListByDateAsync(DateTime dateTime)
  {
      IUnitOfWork unitOfWork = await _dbConnection.GetUnitOfWorkAsync();
      unitOfWork.Begin();
      try
      {
          var partySearchHistories = await unitOfWork
              .Connection
              .QueryAsync&lt;PartySearchHistoryDto&gt;(
              @$&quot;SELECT *
            FROM [dbo].[PartySearchHistories] WITH (NOLOCK)
            WHERE CreatedAt = @dateTime
              AND IsDeleted = 0&quot;,
              new { dateTime },
              transaction: unitOfWork.Transaction);
  
          return partySearchHistories.ToList();
      }
      catch (Exception)
      {
          return new List&lt;PartySearchHistoryDto&gt;();
      }
  }
  </code></pre>
  <p>this code only works if you send exactly the format in the database as a parameter.</p>