5시간코딩
[날짜함수] employee 테이블에서 6개월 후 첫 월요일에 연봉협상 일정을 잡으려고 할 때, 그 날짜를 구해주세요. 본문
[날짜함수] employee 테이블에서 6개월 후 첫 월요일에 연봉협상 일정을 잡으려고 할 때, 그 날짜를 구해주세요.
5시간코딩 2019. 4. 6. 16:091. oracle
1)
select next_day(add_months(hire_date,6),'월요일') from employees;
2)
select next_day(hire_date + to_yminterval('0-6'),'월') from employees;
<참고>
-- select next_day(add_months(sysdate,6),'월요일') from dual;
-- select next_day(sysdate + to_yminterval('0-6'),'월') from dual;
2. r
library(lubridate)
add <- 8 - as.numeric(format(as.Date(emp$HIRE_DATE) + months(6),'%w'))
as.Date(emp$HIRE_DATE) + months(6) + days(add)
#검증 : weekdays(as.Date(emp$HIRE_DATE) + months(6) + days(add))
3. python
import pandas as pd
import datetime
import dateutil
emp=pd.read_csv("c:/data/employees.csv")
emp['HIRE_DATE']=[datetime.datetime.strptime(i,'%Y-%m-%d') for i in emp['HIRE_DATE']]
emp['6MONTH']=[i+dateutil.relativedelta.relativedelta(months=6) for i in emp['HIRE_DATE']]
x = [8-i.weekday() for i in emp['6MONTH']]
res=[]
for i in range(len(emp['6MONTH'])):
res.append(emp['6MONTH'][i] + dateutil.relativedelta.relativedelta(days=x[i]))
print(res)