티스토리 뷰

728x90
import datetime


DAY_OF_WEEK = {
    "MONDAY": 0,
    "TUESDAY": 1,
    "WEDNESDAY": 2,
    "THURSDAY": 2,
    "FRIDAY": 2,
    "SATURDAY": 2,
    "SUNDAY": 6
}

def string_to_date(dt, format='%Y%m%d'):
    return datetime.datetime.strptime(dt, format)

def date_to_string(date, format='%Y%m%d'):
    return datetime.datetime.strftime(date, format)

def day_of_week(dt):
    return string_to_date(dt).weekday()
    

dt = '20210101'
if day_of_week(dt) == DAY_OF_WEEK['SUNDAY']:
    None

https://stackoverflow.com/questions/9847213/how-do-i-get-the-day-of-week-given-a-date/65825404#65825404

 

How do I get the day of week given a date?

I want to find out the following: given a date (datetime object), what is the corresponding day of the week? For instance, Sunday is the first day, Monday: second day.. and so on And then if the ...

stackoverflow.com

https://godoftyping.wordpress.com/2015/04/19/python-%EB%82%A0%EC%A7%9C-%EC%8B%9C%EA%B0%84%EA%B4%80%EB%A0%A8-%EB%AA%A8%EB%93%88/

 

[python] 날짜, 시간관련 모듈

파이썬에서 날짜와 시간을 다루는 방법을 알아보자. 지금 현재의 날짜와 시간을 문자열로 출력하려면 strftime 메서드를 이용하면 된다. 날찌, 시간형식의 문자열을 datetime으로 만들려면 strptime을

godoftyping.wordpress.com

 

728x90

'공부' 카테고리의 다른 글

[Sh] command $? exit() & timer <= 30s failed  (0) 2021.01.21
[Sh] exit()  (0) 2021.01.21
[Python] String to Date; Date to String  (0) 2021.01.19
[Slack] slacker.Error: missing_scope  (0) 2021.01.14
[Chart.js] make chart image  (0) 2021.01.14
댓글