Skip to content

Instantly share code, notes, and snippets.

@zhyq0826
Last active May 31, 2019 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhyq0826/5873700 to your computer and use it in GitHub Desktop.
Save zhyq0826/5873700 to your computer and use it in GitHub Desktop.
python 根据根据日期计算所在周的开始和结束
import datetime
def get_week():
today = datetime.date.today()
month = today.month
year = today.year
day = today.day
weekday = today.weekday()
start = today + datetime.timedelta(0-weekday)
end = today + datetime.timedelta(6-weekday)
start = datetime.datetime(start.year,start.month,start.day)
end = datetime.datetime(start.year,start.month,start.day)
return start, end
@jethrochen
Copy link

老铁,你这是大意失荆州啊
end = datetime.datetime(end.year,end.month,end.day)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment