date
-
String으로 저장된 날짜를 Date 형식으로 변환하여 DB에 저장하기JAVA 2021. 9. 14. 13:11
String 으로 저장된 날짜를 Date 로 바꿔서 DB에 저장해야 할 때가 있다 아래의 예시로 보자 // String인 날짜 String sourceDate = "2021-09-14"; // 날짜 포맷을 생성하고 LocalDate 형태로 변환한다 DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate date = LocalDate.parse(sourceDate, dateTimeFormatter); DB 로 저장할 때는 한번 더 변환이 필요하다 java.sql.Date convertedDate = new java.sql.Date.valueOf(date);
-
DATE Type Select 해서 다른 테이블에 Insert 하기Oracle 2021. 3. 2. 13:13
DATE Type data 를 Select 해서 그대로 다른 테이블에 Insert 를 하는 경우 위와 같이 시간이 없어진 data 가 Insert 된다 이와 같은 경우 DATE data 를 -> TO_CHAR() 후 -> TO_DATE() 로 저장시키면 시간을 그대로 저장할 수 있다 자세히 살펴보자 1. TO_CHAR("원하는 Column", "Column 의 Data 양식") 으로 Select 를 한다 select TO_CHAR(REQUEST_DATE,'YYYY/MM/DD AM HH:MI:SS') AS CONVERT_DATE from print_queue2 order by request_date desc; 2. 저장하고자 하는 테이블에 TO_DATE("저장할 값", "저장할 Data 의 양식") 으로 ..