1. LocalDate 예제
- HttpServletRequest request로 받는 가정합니다.
- qTable에 createDate 컬럼이 있다고 가정합니다.
String startDateStr = request.getParameter("startDate");
String endDateStr = request.getParameter("endDate");
LocalDate startDate = null;
LocalDate endDate = null;
if ( startDateStr != null && !startDateStr.equals("")) {
startDate = LocalDate.parse(startDateStr, DateTimeFormatter.ISO_DATE);
}
if ( endDateStr != null && !endDateStr.equals("")) {
endDateStr = LocalDate.parse(endDateStr, DateTimeFormatter.ISO_DATE);
}
query.from(qTable).where(qTable.createDate.between(startDate, endDate));
2. LocalDateTime 예제
- HttpServletRequest request로 받는 가정합니다.
- qTable에 createdAt 컬럼이 있다고 가정합니다.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
String startDateStr = request.getParameter("startDate");
String endDateStr = request.getParameter("endDate");
LocalDateTime startDate = null;
LocalDateTime endDate = null;
if ( startDateStr != null && !startDateStr.equals("")) {
startDate = LocalDateTime dateTime = LocalDateTime.parse(startDateStr, formatter);
}
if ( endDateStr != null && !endDateStr.equals("")) {
endDate = LocalDateTime dateTime = LocalDateTime.parse(endDateStr, formatter);
}
query.from(qTable).where(qTable.createdAt.between(startDate, endDate));
728x90
댓글