title: How to convert Datetime to Date in JPA query
body: <p>I'm writing complicated queries using Spring data JPA, let's say a statistics query.</p>
  
  <pre><code>@Data
  @AllArgsConstructor
  @NoArgsConstructor
  public class StatisticsPair {
    private LocalDateTime time;
    private BigDecimal balance;
  }
  
  @Data
  @Entity
  @Table(name="t_order")
  public class Order {
    private LocalDateTime createdTime;
    private BigDecimal amount;
    private OrderStatus status;
  }
  </code></pre>
  
  <p>query in a repository:</p>
  
  <pre><code>@Query("select new xxx.StatisticsPair(createdTime, sum(amount)) from Order where createdTime &gt;= ?1 and createdTime &lt;= ?2 and status = xxx.OrderStatus.COMPLETED group by createdTime")
  List&lt;StatisticsPair&gt; statAmountByDay(LocalDateTime from, LocalDateTime to);
  </code></pre>
  
  <p>method <code>statAmountByDay</code> gives me a result like:</p>
  
  <pre><code>[
    {"time": "2006-01-02 15:04:05", "balance": 100.00}
    {"time": "2006-01-02 16:04:05", "balance": 200.00}
    {"time": "2006-01-03 15:04:05", "balance": 200.00}
  ]
  </code></pre>
  
  <p>but I want statistics by day, only need date, time is useless, expected result:</p>
  
  <pre><code>[
    {"time": "2006-01-02", "balance": 300.00}
    {"time": "2006-01-03", "balance": 200.00}
  ]
  </code></pre>
  
  <p>so I want to know how to convert <code>createdTime</code>(datetime type) to <code>Date</code> type, like function <code>DATE(createdTime)</code> in mysql, but I don't wanna use native query, because my code runs on different ENV, use different databases.</p>