sql 周的提取表达

MySQL 

#mysql专用:
#周日开始
concat(str_to_date(concat(yearweek(apply_date), ' Sunday'), '%X%V %W'),"~",date_add(str_to_date(concat(yearweek(apply_date), ' Sunday'), '%X%V %W'),interval 6 day)) AS APPLY_WEE
#周一开始
concat(str_to_date(concat(yearweek(apply_date,1),'Monday'),'%x%v %W'),"~",date_add(str_to_date(concat(yearweek(apply_date,1),'Monday'),'%x%v %W'),interval 6 day)) AS APPLY_WEEK

python

#周一开始
import datetime as dt
def get_monday_to_sunday(today):
    today = dt.datetime.strptime(str(today), "%Y-%m-%d")
    monday = dt.datetime.strftime(today - dt.timedelta(today.weekday()), "%Y-%m-%d")
    monday_ = dt.datetime.strptime(monday, "%Y-%m-%d")
    sunday = dt.datetime.strftime(monday_ + dt.timedelta(monday_.weekday() + 6), "%Y-%m-%d")
    monday1=str(monday)
    sunday1=str(sunday)
    return monday1+"~"+sunday1

数仓(hive或者星环)

#周一开始
concat(DATE_ADD(NEXT_DAY(放款日期,'星期天'),-6),"~",NEXT_DAY(放款日期,'星期天')) week

 

posted on 2023-11-22 17:04  小小喽啰  阅读(54)  评论(0编辑  收藏  举报